\centerline{} command alternative?
The \centerline
command should never be used in a LaTeX document (unless you know precisely what you're doing, and probably only in the preamble for some definition). Use
\begin{figure}[htp]
\centering
<whatever>
\end{figure}
and <whatever>
(a graphic, a TikZ picture or anything) will be centered.
You can use adjustbox
\documentclass{scrreprt}
\usepackage[export]{adjustbox} %% export option makes adjustbox --
%% -- goodies available inside includegraphics command
\usepackage{graphicx}
\begin{document}
X\hrulefill X
\begin{figure}[htp]
\includegraphics[width=1.1\textwidth,center]{example-image-a}
\end{figure}
\end{document}
This is very useful for figures that are wider than \textwidth
. Another useful macro will be adjustbox
environment with max width
option.
\documentclass{scrreprt}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\begin{document}
X\hrulefill X
This is resized to \verb|1.1\textwidth|
\begin{figure}[htp]
\begin{adjustbox}{center,max width=1.1\textwidth}
\includegraphics[width=1.2\textwidth,center]{example-image-a}
\end{adjustbox}
\end{figure}
\clearpage
The following is not resized:
\begin{figure}[htp]
\begin{adjustbox}{center,max width=1.1\textwidth}
\includegraphics[width=0.7\textwidth,center]{example-image-b}
\end{adjustbox}
\end{figure}
\end{document}
The advantage of max width
is that the content is resized only if it exceeds the max width
otherwise not.
With tikzpicture
environment
I assume that your tikz picture are saved as separate files. Then using adjustbox
and tikzscale
packages:
\documentclass{article}
\usepackage{graphicx,tikz,tikzscale}
\usepackage{adjustbox}
\usepackage{filecontents}
\begin{filecontents*}{myfig.tikz}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt]
\draw[use as bounding box](-20,-20) rectangle (20,20);
\node at (0,0) (A) {A};
\node[above right] (B) at (A.north east) {B};
\draw (A.south west)--(B.north east);
\end{tikzpicture}
\end{filecontents*}
\begin{document}
X\hrulefill X
This is resized to \verb|1.1\textwidth|
\begin{figure}[htp]
\begin{adjustbox}{max width=1.1\textwidth,center}
\includegraphics[width=1.2\textwidth]{myfig.tikz}
\end{adjustbox}
\end{figure}
\clearpage
The following is not resized:
\begin{figure}[htp]
\begin{adjustbox}{max width=1.1\textwidth,center}
\includegraphics[width=0.7\textwidth]{myfig.tikz}
\end{adjustbox}
\end{figure}
\end{document}