Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm having trouble aligning text inside a TikZ table. It currently just centres the middle letter, despite the align=left.

I also tried using:

row 1/.style={nodes={align=left}}

(as suggested in Creating table using TikZ matrix)

Table text alignment

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}

\tikzset
  { 
    table/.style={matrix of nodes,
                  row sep=-\pgflinewidth,
                  column sep=-\pgflinewidth,
                  nodes={rectangle,
                         draw=black,
                         text width=2ex,
                         align=left,
                         minimum width=1.5cm
                        },
                  text depth=0.25ex,
                  text height=2ex,
                  nodes in empty cells
                 },
    texto/.style={font=\footnotesize\sffamily},
    title/.style={font=\small\sffamily},
    my top text/.style={font=\small\sffamily},
    my bottom text/.style={font=\sffamily\footnotesize}
  }

\newcommand\CellText[2]{%
  \node[texto,left=of mat#1,anchor=east]
  at (mat#1.west)
  {#2};
}

\newcommand\SlText[2]{\node[my top text,anchor=base] at ($(mat#1.north)+(0,1.0ex)$) {#2};}
\newcommand\SIundertext[2]{\node[my bottom text,anchor=base] at ($(mat#1.south west)-(0,2.0ex)$) {#2};}

\newcommand\RowTitle[2]{%
\node[title,left=6.3cm of mat#1,anchor=west]
  at (mat#1.north west)
  {#2};
}
\begin{document}

\begin{tikzpicture}[node distance=0pt and 0.5cm]

  \matrix[table] (mat11) {  1,53& |[draw=none,alias=gap A]| & 22 & 22 & 22,24  & |[draw=none,alias=gap B]| & 1 \\ };

  \foreach \x/\y in {1/$0$,
                     3/$h-1$,
                     4/$h$,
                     5/$h+1$,
                     7/$b$}
  { \SlText{11-1-\x}{\y} }

  \foreach \x/\y in {1/$0$,
                     2/$\epsilon$,
                     3/$(h-2)\epsilon$,
                     4/$(h-1)\epsilon$,
                     5/$h\epsilon$,
                     6/$(h+1)\epsilon$,
                     7/$\xi\epsilon$}
    { \SIundertext{11-1-\x}{\y} }
    \node at (mat11-1-2.center) {$\ldots$};
    \node at (mat11-1-6.center) {$\ldots$};
    \node[my bottom text] at ($(mat11-1-7.south east)-(0,1.5ex)$) { $(\xi+1)\epsilon$ };

  %% create ragged edges for ellipsis in time line
  \coordinate (intrusion for box)     at (1.75ex,   0  );
  \coordinate (vertical border adj)   at (  0  , 0.2pt);
  \coordinate (horizontal border adj) at (0.2pt,   0  );

  \foreach \x in {A,B}{
  \draw ($(gap \x.south west)+(intrusion for box)+(vertical border adj)$)     -- 
        ($(gap \x.south west)+(horizontal border adj)+(vertical border adj)$) --
        ($(gap \x.north west)+(horizontal border adj)-(vertical border adj)$) --
        ($(gap \x.north west)+(intrusion for box)-(vertical border adj)$);                                                                                                                   
  \draw [decorate,decoration={zigzag,segment length=4pt,amplitude=2pt}]                                                                                                                      
        ($(gap \x.north west)+(intrusion for box)-(vertical border adj)$) --
        ($(gap \x.south west)+(intrusion for box)+(vertical border adj)$);

  \draw ($(gap \x.south east)-(intrusion for box)+(vertical border adj)$)     -- 
        ($(gap \x.south east)-(horizontal border adj)+(vertical border adj)$) --
        ($(gap \x.north east)-(horizontal border adj)-(vertical border adj)$) --
        ($(gap \x.north east)-(intrusion for box)-(vertical border adj)$);
  \draw [decorate,decoration={zigzag,segment length=4pt,amplitude=2pt}]                                                                                                                      
        ($(gap \x.north east)-(intrusion for box)-(vertical border adj)$) --
        ($(gap \x.south east)-(intrusion for box)+(vertical border adj)$);
  }

  \node[my top text,anchor=base east]    at ($(mat11-1-1.north west)-(2ex,0)+(0,1.0ex)$) {Bin};
  \node[my bottom text,anchor=base east] at ($(mat11-1-1.south west)-(2ex,0)-(0,2.0ex)$) {Time};
  \node[title,anchor=east]          at ($(mat11-1-1.west)-(1.5cm,0)$) {Vehicle $k$};

\end{tikzpicture}
\end{document}

Previous question where I was very kindly helped to this point can be found in TikZ table with floating labels + time discontinuity.

share|improve this question
1  
minimum width is only the width of the node (including inner xseps and the width of the text box), text width is the actual with of the text box. The align key changes the alignment of text inside the text box not the alignment of the text box inside the node. –  Qrrbrbirlbel Sep 22 '13 at 13:07
    
You can find other solutions in create-an-array-in-tikz-with-underbrace-in-different-colors –  Ignasi Sep 22 '13 at 20:57
add comment

1 Answer 1

up vote 4 down vote accepted

2ex is too short for allowing any alignment. If I use

text width=1.5cm,

in the table style, I get

enter image description here

such that there is room for text to be aligned differently

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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