3

I want to align the arrows so that it goes directly through the "x". How can I do this? It works if I use \normalsize font.

The background is that I want to separate my Tikz document in text rows where I can position objects easily by a multiple of e.g. \baselineskip (\baselineskip seems to be wrong. It only works for \normalsize font).

This is a follow-up question from Size of \baselineskip for \\ if font size is \footnotesize?. I am not sure but I think I need "node font=\footnotesize" which is only available in Tikz 3.0.

\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[every node/.style={node font=\footnotesize, font=\footnotesize}]
    \node[anchor=north west, inner sep=0, rectangle, red, draw, 
          text width=0.5cm, align=left](A) {%
          \strut x\\
          x\strut
    };
    \draw[->] (0.1cm, -0.5\baselineskip) -- (1cm, -0.5\baselineskip);
    \draw[->] (0.1cm, -\baselineskip-0.5\baselineskip) -- (1cm, -\baselineskip-0.5\baselineskip);
\end{tikzpicture}

\end{document}

enter image description here

It should looks likes this (you get this result if "every node/.style={node font=\footnotesize, font=\footnotesize}" is removed):

enter image description here

1 Answer 1

1

\tikzmark would save you some calculations. By the way, node font doesn't seem to be a valid key in TikZ.

Code

\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand\tikzmark[2][]{\tikz[remember picture]\node(#1)[minimum height=1ex,text width=1ex]{#2};}

\begin{document}

\begin{tikzpicture}[remember picture,font=\footnotesize]
    \node[anchor=north west, inner sep=0, rectangle, red, draw, 
          text width=0.5cm, align=left](A) {%
          \strut \tikzmark[n1]{x}\\
          \tikzmark[n2]{x}\strut
    };
    \draw[->](n1.center)--+(1,0);
    \draw[->](n2.center)--+(1,0);
\end{tikzpicture}

\end{document}

Output

enter image description here

1
  • Thanks, but is there another way without using \tikzmark? I want to separate my Tikz document in text rows which I then can access via multiples of \baselineskip (or other length).
    – user4811
    Commented Jan 8, 2014 at 19:46

You must log in to answer this question.

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