1

In the following code, TikZ is to draw four nodes at the vertices of a parallelogram. In two of the nodes, I would like to put two lines of text. I indicate this using //. I thought that using the contents option would allow for that.

To draw the edges of the parallelogram, should I first label the coordinates something like A, B, C, and D, and proceed to issue a command like \draw (A) -- (B) -- (C) -- (D) -- cycle?

What is the command to put the nodes in the foreground? What is the command to add a bit of space between the border of the node at (2,4) and the two line segments going toward it?

\documentclass{amsart}
\usepackage{tikz}
        \usetikzlibrary{calc,angles,shapes,positioning,intersections,quotes,decorations.markings}        
\begin{document}

\begin{tikzpicture}

\path (0,0) node [red] {origin}
(1,3) node[blue]{node contents={upper \\ left}}
(2,4) node[green]{diagonal}
(3,2) node[node contents={lower \\ right}] ;

\end{tikzpicture}

\end{document}
Adelyn
  • 3,373

2 Answers2

4

Why all that typing?

\documentclass{amsart}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}

\draw[red,fill=yellow] (0,0) node [below left,red] {origin} --
(3,5) node[blue, align=center,above left]{upper \\ left} --
(8,8) node[green,above]{diagonal} --
(5,3) node[below right,align=center]{lower \\ right} -- cycle ;

\end{tikzpicture}

\end{document}

enter image description here

  • Thanks. In an effort to familiarize myself with TikZ, I was separating the declaration of nodes indicating the vertices of a parallelogram in a \path command from the drawing of its edges in a \draw command. – Adelyn Apr 16 '15 at 13:12
1

If you just want to move the nodes so they don't interfere with the shape you can you xshift and yshift to fine tune their positions. You can also use anchors as you suggested.

enter image description here

\documentclass{amsart}
\usepackage{tikz}  
\begin{document}

\begin{tikzpicture}
\draw[fill=yellow] (0,0) -- (3,5) -- (8,8) -- (5,3) -- cycle;
\node[red, xshift=-1em, yshift=-1em] at (0,0) (A) {origin};
\node[blue, yshift=1em, xshift=-1em] at (3,5) (B) {\begin{tabular}{c}
upper \\
left \\
\end{tabular}};
\node at (8,8) [green, yshift=1em, xshift=1em] (C) {diagonal};
\node at (5,3) [yshift=-1.5em, xshift=1em] (D) {\begin{tabular}{c}
lower \\
right \\
\end{tabular}};
\end{tikzpicture}

\end{document}

As a note on the colour, remember you can use fill=yellow!20 to change the shade by varying the number.

Christopher
  • 1,336
  • 11
  • 19
  • Very nice! What units of the xshift and yshift are allowed? You used em. I guess you can use mm, cm, and pt. Can you use the coordinate system?

    There is one more feature that I would like to add to your display. How do I color the region enclosed by the parallelogram yellow?

    – Adelyn Apr 15 '15 at 21:09
  • You can indeed use those units, I tend to use em as it is a relative unit. I'm not sure what you mean by using the coordinate system. As for colouring the shape you just add [fill=yellow] as an option to draw. I'll update the answer to reflect this. – Christopher Apr 15 '15 at 21:14
  • @ Christopher I plotted the vertices of the parallelogram using the coordinate system. If you type xshirft=-0.1, yshift=-0.1, would that move a vertex diagonally? Thanks for the code to color the region enclosed by the parallelogram. – Adelyn Apr 15 '15 at 22:09
  • I don't think this will work as there is no unit. You could create a different node and place it using the coordinate system though. Why you would want to though is a mystery. – Christopher Apr 16 '15 at 07:24
  • You're right. I can "shift" the node by positioning it differently. I am looking for consistency in all the displays in a chapter. Having just started to familiarize myself with TikZ, I have not decided how to consistently "shift" nodes. – Adelyn Apr 16 '15 at 13:07