0

I am facing the following problem pictured below

enter image description here

The code is the following

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{center}
\begin{tikzpicture}

\path[draw, line width=1pt] (0,5) -- (4,5) -- (2,8.45) -- cycle;
\path[draw, line width=1pt] (7,5) -- (11,5) -- (9,8.45) -- cycle;
\path[draw, line width=1pt] (14,5) -- (18,5) -- (16,8.45) -- cycle;
\path[draw, line width=1pt] (0,0) -- (4,0) -- (2,3.45) -- cycle;
\path[draw, line width=1pt] (7,0) -- (11,0) -- (9,3.45) -- cycle;
\path[draw, line width=1pt] (14,0) -- (18,0) -- (16,3.45) -- cycle;

\end{tikzpicture}
\end{center}

\end{document}

I do not know exactly why the whole picture seems to be shifted to the right although placed in a \center enviroment. It appears to be that there is (obviously) some kind of maximal width. But I have no clue how to adjust the \tikzpicture enviroment accordingly.

Two questions: first, why does the tikz-picture starts after a left margin? Second, why does the tikz-picture extends the right hand border?

Thanks in advance!

Bonus question: If some could explain how to make the triangle actually equilateral, that would be great!

1 Answer 1

3

Your picture is too wide (more than the value of \textline). You should receive a warning like Overfull \hbox (168.54938pt too wide) in paragraph at lines 30--31

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\begin{document}

\begin{center}
Your textline is \convertto{cm}{\the\textwidth} cm wide.

\begin{tikzpicture}
\path[draw, line width=1pt] (0,5) -- (4,5) -- (2,8.45) -- cycle;
\path[draw, line width=1pt] (7,5) -- (11,5) -- (9,8.45) -- cycle;
\path[draw, line width=1pt] (14,5) -- (18,5) -- (16,8.45) -- cycle;
\path[draw, line width=1pt] (0,0) -- (4,0) -- (2,3.45) -- cycle;
\path[draw, line width=1pt] (7,0) -- (11,0) -- (9,3.45) -- cycle;
\path[draw, line width=1pt] (14,0) -- (18,0) -- (16,3.45) -- cycle;
\draw (current bounding box.south east) -- (current bounding box.north east)
  -- (current bounding box.north west) -- (current bounding box.south west)
  -- cycle;
\path let \p1 = (current bounding box.south east) in
  let \p2 = (current bounding box.south west) in
  let \n1 = {\x1 - \x2} in
  \pgfextra{\pgfmathsetmacro{\temp}{\n1 / 1cm}}
  (current bounding box.south) node[below] {Your picture is \temp cm wide};

\end{tikzpicture}
\end{center}

\end{document}

enter image description here

Use scale option to fit your picture to the line width.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\begin{document}

\begin{center}
Your textline is \convertto{cm}{\the\textwidth} cm wide.

\begin{tikzpicture}
\begin{scope}[scale=0.6]
  \path[draw, line width=1pt] (0,5) -- (4,5) -- (2,8.45) -- cycle;
  \path[draw, line width=1pt] (7,5) -- (11,5) -- (9,8.45) -- cycle;
  \path[draw, line width=1pt] (14,5) -- (18,5) -- (16,8.45) -- cycle;
  \path[draw, line width=1pt] (0,0) -- (4,0) -- (2,3.45) -- cycle;
  \path[draw, line width=1pt] (7,0) -- (11,0) -- (9,3.45) -- cycle;
  \path[draw, line width=1pt] (14,0) -- (18,0) -- (16,3.45) -- cycle;
\end{scope}
\draw (current bounding box.south east) -- (current bounding box.north east)
  -- (current bounding box.north west) -- (current bounding box.south west)
  -- cycle;
\path let \p1 = (current bounding box.south east) in
  let \p2 = (current bounding box.south west) in
  let \n1 = {\x1 - \x2} in
  \pgfextra{\pgfmathsetmacro{\temp}{\n1 / 1cm}}
  (current bounding box.south) node[below] {Your picture is \temp cm wide};

\end{tikzpicture}
\end{center}

\end{document}

enter image description here

1
  • Yes, indeed, this error occured but clearly I've not paid enough attention to this! Thank you kindly!
    – mrtaurho
    Jun 3, 2020 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .