4

I have this code:

\documentclass{tufte-latex}
\usepackage{tikz}

\begin{document}

\section{Some variables to play with}


\subsection{Time}


    \begin{tikzpicture}[place/.style={circle,draw=gray,fill=gray,very thick}]

                \sffamily

                % put points on graph  
                \node (n1) at (1,0) [place,label=below:{Alternate past}] {};
                \node (n2) at (3,0) [place,label=below:{Present}] {};
                \node (n3) at (5,0) [place,label=below:{Near future}] {};
                \node (n4) at (7,0) [place,label=below:{Far future}] {};


                % \foreach \x [evaluate={\y=int(\x+1);}] in {1,...,9}
                \draw[gray,very thick] (1,0) -- (7,0);
    \end{tikzpicture}



    \subsection{Hard vs. soft SF}

    \begin{tikzpicture}[place/.style={circle,draw=gray,fill=gray,very thick}]

                \sffamily

                % put points on graph  
                \node (n1) at (1,0) [place,label=below:{2001}] {};
                \node (n2) at (3,0) [place,label=below:{Alien}] {};
                \node (n3) at (5,0) [place,label=below:{Blade Runner}] {};
                \node (n4) at (7,0) [place,label=below:{WOTW}] {};


                % \foreach \x [evaluate={\y=int(\x+1);}] in {1,...,9}
                \draw[gray,very thick] (1,0) -- (7,0);
    \end{tikzpicture}


    \subsection{Optimism vs. pessimism}


    \begin{tikzpicture}[place/.style={circle,draw=gray,fill=gray,very thick}]

                \sffamily

                % put points on graph  
                \node (n1) at (1,0) [place,label=below:{Star Trek}] {};
                \node (n2) at (3,0) [place,label=below:{Neutron Star}] {};
                \node (n3) at (5,0) [place,label=below:{WOTW}] {};
                \node (n4) at (7,0) [place,label=below:{New Rose Hotel}] {};


                % \foreach \x [evaluate={\y=int(\x+1);}] in {1,...,9}
                \draw[gray,very thick] (1,0) -- (7,0);
    \end{tikzpicture}

\end{document}

Which produces this result: sf_spectra_test

I want to align the three continua so that the nodes are lined up with each other. What is the best way to do that?

2
  • There is no class called tufte-latex, did you mean tufte-book? Try every label/.style={text width=3cm,align=center} Apr 25, 2017 at 12:18
  • 1
    I actually meant `tufte-handout'. That solution worked. Happy to accept a formal answer if you want the credit.
    – crmdgn
    Apr 25, 2017 at 12:28

3 Answers 3

9

The reason for this is of course that the leftmost labels have different widths. Hence, a workaround is to set the text width of all the labels to the same, with e.g.

every label/.style={text width=3cm,align=center}

The 3cm may have to be adjusted, depending on the labels themselves.


Addendum: strictly speaking, you only need to do this for the leftmost node, as AboAmmar points out in his answer.

Hence, you could just modify your code to have, e.g. for the first diagram,

label={[text width=3cm,align=center]below:Alternate past}

Or, for the code I posted below, remove the text width=3cm,align=center from the widelabels style, and use \node [place,"Alternate past" {widelabels,text width=3cm,align=center}] (n1) {};


Just for fun, here is a suggestion for an alternative approach to drawing such things, using the chains and quotes libraries. With chains you can get automatic positioning and joining of the nodes, and the quotes library provides an alternative method for adding labels.

\documentclass{tufte-handout}    
\usepackage{tikz}
\tikzset{
  place/.style={circle,draw=gray,fill=gray,very thick,on chain,join},
  widelabels/.style={below,text width=3cm,align=center,font=\sffamily},
  mychain/.style={start chain,node distance=2cm,every join/.style={gray, very thick}}
}
\usetikzlibrary{quotes,chains}
\begin{document}

\section{Some variables to play with}


\subsection{Time}

\begin{tikzpicture}[mychain]

  % put points on graph  
  \node [place,"Alternate past" widelabels] (n1) {};
  \node [place,"Present" widelabels] (n2)  {};
  \node [place,"Near future" widelabels](n3)  {};
  \node [place,"Far future" widelabels](n4) {};

\end{tikzpicture}


\subsection{Hard vs. soft SF}
\begin{tikzpicture}[mychain]

  % put points on graph  
  \node [place,"2001" widelabels] (n1) {};
  \node [place,"Alien" widelabels] (n2)  {};
  \node [place,"Blade runner" widelabels](n3)  {};
  \node [place,"WOTW" widelabels](n4) {};

\end{tikzpicture}


\subsection{Optimism vs. pessimism}

\begin{tikzpicture}[mychain]

  % put points on graph  
  \node [place,"Star Trek" widelabels] (n1) {};
  \node [place,"Neutron Star" widelabels] (n2)  {};
  \node [place,"WOTW" widelabels](n3)  {};
  \node [place,"New Rose Hotel" widelabels](n4) {};

\end{tikzpicture}
\end{document}

enter image description here

5

Torbjørn has already explained the problem and shown how to fix it - so give him the green tick. I want to suggest an approach that is easier to read and maintain: use a macro for the tikzpicture environments.

Here is a more compact version of your MWE:

\documentclass{tufte-book}
\usepackage{tikz}

%usage: \linegraph{item1,item2, ...}
\newcommand\linegraph[1]{%
    \begin{tikzpicture}[place/.style={circle,draw=gray,fill=gray,very thick, radius=1mm},
                        every label/.style={text width=3cm,align=center}
                        ]
        \foreach \word [count=\x, remember=\x as \lastx] in {#1} {
                \node (n\x) at (2*\x-1,0) [place,label=below:{\word}] {};
        }
        \draw[gray,very thick] (1,0) -- (2*\lastx-1,0);
    \end{tikzpicture}
    }

\begin{document}

\section{Some variables to play with}

    \subsection{Time}

    \linegraph{Alternate past, Present, Near future, Far future}

    \subsection{Hard vs. soft SF}

    \linegraph{2001, Alien, Blade runner, WOTW}

    \subsection{Optimism vs. pessimism}

    \linegraph{Star Trek, Neutron Star, WOTW, New Rose Hotel}

\end{document}

I have put node labels n1, n2, .., etc into \linegraph but as currently written they should be dropped because they are not used. Also, \linegraph will accept any number of items - up to the page width of course. The output is the same as above:

enter image description here

Of course, you could do something similar using chains as Torbjørn has done.

3

Yet another easy fix is to just align the three left-most labels and every thing else will be kept intact. Use, for example, this command \newcommand{\ALIGN}[1]{\makebox[6em]{#1}} to align these nodes.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\section{Some variables to play with}

\subsection{Time}

\newcommand{\ALIGN}[1]{\makebox[6em]{#1}}

    \begin{tikzpicture}[place/.style={circle,draw=gray,fill=gray,very thick}]
                \sffamily
                % put points on graph  
                \node (n1) at (1,0) [place,label=below:\ALIGN{Alternate past}] {};
                \node (n2) at (3,0) [place,label=below:{Present}] {};
                \node (n3) at (5,0) [place,label=below:{Near future}] {};
                \node (n4) at (7,0) [place,label=below:{Far future}] {};

                \draw[gray,very thick] (1,0) -- (7,0);
    \end{tikzpicture}

    \subsection{Hard vs. soft SF}

    \begin{tikzpicture}[place/.style={circle,draw=gray,fill=gray,very thick}]
                \sffamily
                % put points on graph  
                \node (n1) at (1,0) [place,label=below:\ALIGN{2001}] {};
                \node (n2) at (3,0) [place,label=below:{Alien}] {};
                \node (n3) at (5,0) [place,label=below:{Blade Runner}] {};
                \node (n4) at (7,0) [place,label=below:{WOTW}] {};

                \draw[gray,very thick] (1,0) -- (7,0);
    \end{tikzpicture}

    \subsection{Optimism vs. pessimism}

    \begin{tikzpicture}[place/.style={circle,draw=gray,fill=gray,very thick}]
                \sffamily
                % put points on graph  
                \node (n1) at (1,0) [place,label=below:\ALIGN{Star Trek}] {};
                \node (n2) at (3,0) [place,label=below:{Neutron Star}] {};
                \node (n3) at (5,0) [place,label=below:{WOTW}] {};
                \node (n4) at (7,0) [place,label=below:{New Rose Hotel}] {};

                \draw[gray,very thick] (1,0) -- (7,0);
    \end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

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