3

I am working on a Tikz picture of a calendar. The headings of the calendar are the months and I add them with nodes. But they aren't aligned.

\begin{tikzpicture}[scale = 1.3]
\path (0,0)node[minimum height = 1cm]{sep}
  (1,0)node[minimum height = 1cm]{oct}
  (2,0)node[minimum height = 1cm]{nov}
  (3,0)node[minimum height = 1cm]{dec}
  (4,0)node[minimum height = 1cm]{jan}
  (5,0)node[minimum height = 1cm]{feb}
  (6,0)node[minimum height = 1cm]{mar}
  (7,0)node[minimum height = 1cm]{apr}
  (8,0)node[minimum height = 1cm]{mei};
\foreach \x in {-0.5,0.5,...,8.5}
  \draw (\x,-0.3)--(\x,-5);
  \draw [fill = green] (-0.5,-1)rectangle node{Studie}(1.5,-1.5);
  \draw [fill = green] (1.5,-1.7)rectangle node{Structuur}(3.5,-2.2);
  \draw [fill = green] (3.5,-2.4) rectangle node{Dimensionering}(6,-2.9);
  \draw [fill = green] (6,-3.1) rectangle node {Interface} (8,-3.6);
\end{tikzpicture}

How do I force the text to be on one line?

3

You need to read the paragraph Positioning Nodes Using Anchors [anchor=base] is a possibility. I compact your code a little

\documentclass[11pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale = 1.3]

 \foreach \m [count=\mi from 0] in {sep,oct,nov,dec,jan,feb,mar,apr,mei}
 \path[anchor=base] (\mi,0) node {\m} ;

\foreach \x in {-0.5,0.5,...,8.5}  \draw (\x,-0.3)--(\x,-5);

      \draw [fill = green]
        (-0.5,-1)   rectangle node {Studie}         (1.5,-1.5)
        (1.5,-1.7)  rectangle node {Structuur}      (3.5,-2.2)
        (3.5,-2.4)  rectangle node {Dimensionering} (6,-2.9)
        (6,-3.1)    rectangle node {Interface}      (8,-3.6);

\end{tikzpicture}

\end{document}

enter image description here

| improve this answer | |
3

Just specify the base anchor for these nodes, then the text is aligned on its baseline:

Sample output

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale = 1.3]
\path[anchor=base] (0,0)node[minimum height = 1cm]{sep}
  (1,0)node[minimum height = 1cm]{oct}
  (2,0)node[minimum height = 1cm]{nov}
  (3,0)node[minimum height = 1cm]{dec}
  (4,0)node[minimum height = 1cm]{jan}
  (5,0)node[minimum height = 1cm]{feb}
  (6,0)node[minimum height = 1cm]{mar}
  (7,0)node[minimum height = 1cm]{apr}
  (8,0)node[minimum height = 1cm]{mei};
\foreach \x in {-0.5,0.5,...,8.5}
  \draw (\x,-0.3)--(\x,-5);
  \draw [fill = green] (-0.5,-1)rectangle node{Studie}(1.5,-1.5);
  \draw [fill = green] (1.5,-1.7)rectangle node{Structuur}(3.5,-2.2);
  \draw [fill = green] (3.5,-2.4) rectangle node{Dimensionering}(6,-2.9);
  \draw [fill = green] (6,-3.1) rectangle node {Interface} (8,-3.6);
\end{tikzpicture}
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.