I am trying to draw a rectangle with a diagonal which are horizontally centered on the page. I tried
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%The rectangle:
\draw (-4,-2) -- (4,-2) -- (4, 2) -- (-4,2) -- cycle;
%The diagonal:
\draw (-4,2) -- (4,-2);
\end{tikzpicture}
\end{document}
which gives me the desired figure, but it is too much to the left. When I add
[shift = {((4 cm, 0 cm))}]
to either the rectangle or the the diagonal , it shifts the appropriate component pretty close to the center of the page. However, if I add this command to both components, as in
\draw [shift = {((4 cm, 0 cm))}] (-4,-2) -- (4,-2) -- (4, 2) -- (-4,2) -- cycle;
\draw [shift = {((4 cm, 0 cm))}] (-4,2) -- (4,-2);
then it looks like I haven't added it to either; the picture is displayed on the left of the page.
Is there a better way to center the triangle and its diagonal on the left of the page, or is there a way to fix this approach? Thank you very much.
Normal text.
– Jun 30 '19 at 14:08, see the answers to https://tex.stackexchange.com/q/61112/121799, or use\begin{center}\begin{tikzpicture} \draw (-4,-2) rectangle (4, 2) (-4,2) -- (4,-2); \end{tikzpicture}\end{center}`. The second possibility adds some vertical space.