3

I have the following tikz diagram. The node labels on the right hand side are all nicely aligned, but the ones on the left are not. How can I left-justify the labels of those nodes and make the lines all come out nicely?

enter image description here

\documentclass{standalone} 
\usepackage{tikz}

\tikzset{ myblock/.style={draw,text width=20pt,minimum height=40pt,align=center}}

\begin{document}

\begin{tikzpicture}
 \node[myblock] (L) {$\Lambda$};

 \node[left=50pt,yshift=10pt] (A1) {$\mathsf{A}$};
 \node[left=50pt,yshift=-10pt] (A'1) {$\mathsf{A}'$};
 \node[left=50pt,yshift=-30pt] (B1) {$\mathsf{B}$};
 \node[left=50pt,yshift=-50pt] (B'1) {$\mathsf{B}'$};
 \node[right=50pt,yshift=10pt] (A2) {$\mathsf{A}$};
 \node[right=50pt,yshift=-10pt] (A'2) {$\mathsf{A}'$};
 \node[right=50pt,yshift=-30pt] (B2) {$\mathsf{B}$};
 \node[right=50pt,yshift=-50pt] (B'2) {$\mathsf{B}'$};

 \draw (A1) to ([shift={(0pt,10pt)}]L.west);
 \draw (B1) to[out=0, in=180] ([shift={(0pt,-10pt)}]L.west);
 \draw ([shift={(0pt,10pt)}]L.east) to (A2);
 \draw ([shift={(0pt,-10pt)}]L.east) to[out=0, in=180] (B2);
 \draw (A'1) to[out=0, in=180] ([shift={(0pt,-30pt)}]L.west) to ([shift=
{(0pt,-30pt)}]L.east) to[out=0, in=180] (A'2);
 \draw (B'1) to (B'2);
\end{tikzpicture}

\end{document}

3 Answers 3

5

Why don't simply use align=left with some little dimension adjustment (text width=.9em, inner xsep=1pt)?

\documentclass{standalone} 
\usepackage{tikz}

\tikzset{ 
    myblock/.style={
        draw,
        text width=20pt,
        minimum height=40pt,
        align=center
    },
    mylittle/.style={
        text width=.9em,
        align=left,
        inner xsep=1pt
    }
}

\begin{document}

    \begin{tikzpicture}
    \node[myblock] (L) {$\Lambda$};

    \node[left=50pt,yshift=10pt,mylittle] (A1) {$\mathsf{A}$};
    \node[left=50pt,yshift=-10pt,mylittle] (A'1) {$\mathsf{A}'$};
    \node[left=50pt,yshift=-30pt,mylittle] (B1) {$\mathsf{B}$};
    \node[left=50pt,yshift=-50pt,mylittle] (B'1) {$\mathsf{B}'$};
    \node[right=50pt,yshift=10pt] (A2) {$\mathsf{A}$};
    \node[right=50pt,yshift=-10pt] (A'2) {$\mathsf{A}'$};
    \node[right=50pt,yshift=-30pt] (B2) {$\mathsf{B}$};
    \node[right=50pt,yshift=-50pt] (B'2) {$\mathsf{B}'$};

    \draw (A1) to ([shift={(0pt,10pt)}]L.west);
    \draw (B1) to[out=0, in=180] ([shift={(0pt,-10pt)}]L.west);
    \draw ([shift={(0pt,10pt)}]L.east) to (A2);
    \draw ([shift={(0pt,-10pt)}]L.east) to[out=0, in=180] (B2);
    \draw (A'1) to[out=0, in=180] ([shift={(0pt,-30pt)}]L.west) to ([shift=
    {(0pt,-30pt)}]L.east) to[out=0, in=180] (A'2);
    \draw (B'1) to (B'2);
    \end{tikzpicture}
\end{document}

enter image description here

0
4

You can fake the space.

phantom

\documentclass{standalone} 
\usepackage{tikz}

\tikzset{ myblock/.style={draw,text width=20pt,minimum height=40pt,align=center}}

\begin{document}

\begin{tikzpicture}
 \node[myblock] (L) {$\Lambda$};

 \node[left=50pt,yshift=10pt] (A1) {$\mathsf{A}\phantom{'}$};
 \node[left=50pt,yshift=-10pt] (A'1) {$\mathsf{A}'$};
 \node[left=50pt,yshift=-30pt] (B1) {$\mathsf{B}\phantom{'}$};
 \node[left=50pt,yshift=-50pt] (B'1) {$\mathsf{B}'$};
 \node[right=50pt,yshift=10pt] (A2) {$\mathsf{A}$};
 \node[right=50pt,yshift=-10pt] (A'2) {$\mathsf{A}'$};
 \node[right=50pt,yshift=-30pt] (B2) {$\mathsf{B}$};
 \node[right=50pt,yshift=-50pt] (B'2) {$\mathsf{B}'$};

 \draw (A1) to ([shift={(0pt,10pt)}]L.west);
 \draw (B1) to[out=0, in=180] ([shift={(0pt,-10pt)}]L.west);
 \draw ([shift={(0pt,10pt)}]L.east) to (A2);
 \draw ([shift={(0pt,-10pt)}]L.east) to[out=0, in=180] (B2);
 \draw (A'1) to[out=0, in=180] ([shift={(0pt,-30pt)}]L.west) to ([shift=
{(0pt,-30pt)}]L.east) to[out=0, in=180] (A'2);
 \draw (B'1) to (B'2);
\end{tikzpicture}

\end{document}
2

An alternative to TeXnician's nice trick is to do the alignment with a table or an array. The whole point of this post is that LaTeX has a very powerful alignment tools, and it is sometimes easier to use these and add the tikZ stuff as an overlay.

\documentclass{article}
\usepackage{amsmath} 
\usepackage{tikz} 

\newcommand{\tikznode}[2]{%
\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$#2$};%
}%from https://tex.stackexchange.com/questions/402462/tikz-equivalent-of-pstricks-commands-ncbar-and-rnode/402466#402466

\tikzset{ myblock/.style={draw,text width=20pt,minimum height=40pt,align=center}}

\begin{document}
\[
\begin{array}{lp{4cm}l}
\tikznode{A1}{\mathsf{A}} & & \tikznode{A2}{\mathsf{A}} \\[0.7cm]
\tikznode{A'1}{\mathsf{A}'} & & \tikznode{A'2}{\mathsf{A}'} \\[0.7cm]
\tikznode{B1}{\mathsf{B}} & & \tikznode{B2}{\mathsf{B}} \\[0.7cm]
\tikznode{B'1}{\mathsf{B}} & & \tikznode{B'2}{\mathsf{B}'} \\[0.7cm]
\end{array}
\]
\begin{tikzpicture}[remember picture,overlay]
 \draw (A1) -- (A2);
 \path (A1) -- (A'2) node[midway,myblock,fill=white] (L) {$\Lambda$};
 \draw (B1) to[out=0, in=180] ([shift={(0pt,-10pt)}]L.west);
 \draw ([shift={(0pt,-10pt)}]L.east) to[out=0, in=180] (B2);
 \draw (A'1) to[out=0, in=180] ([shift={(0pt,-40pt)}]L.west) to ([shift=
{(0pt,-40pt)}]L.east) to[out=0, in=180] (A'2);
 \draw (B'1) to (B'2);
\end{tikzpicture}

enter image description here

2
  • Nice, but now the lines are all funky! Can you get the lines to be horizontal and match up again?
    – markoman
    Jan 10, 2018 at 20:55
  • @luftbahnfahrer I edited the post to make the lines less funky. Does that come closer to what you want?
    – user121799
    Jan 10, 2018 at 21:55

You must log in to answer this question.

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