1

I'd like the tikzmark to be centered on the line of the tabular, the optional argument seems not working or I missuse it :

enter image description here

\documentclass{article}
\usepackage{tikz,array}

\usetikzlibrary{tikzmark}

\begin{document}

\renewcommand{\arraystretch}{1.2}

\begin{tabular}{|c|}\noalign{\tikzmark[yshift=-5pt]{Z0}}\hline
foo
\end{tabular}

\tikz[overlay,remember picture]
    \fill[orange] (pic cs:Z0) circle (.5pt) ;

\begin{tabular}{|c|}\noalign{\tikzmark[yshift=-5pt]{Z1}}
foo
\end{tabular}

\tikz[overlay,remember picture]
    \fill[orange] (pic cs:Z1) circle (.5pt) ;

\end{document}
1

I guess it's the same reason why \begin{tikzpicture}[yshift=-5pt] wouldn't move a tikzpicture down. The option is applied to the content of the tikzpicture in the coordinate system of the diagram, but it doesn't affect the position of the tikzpicture on the baseline/page.

On the other hand, foo\raisebox{5pt}{\tikzmark{Z0}}\tikzmark{Z1}bar \tikz[overlay,remember picture] \draw[orange] (pic cs:Z0) -- (pic cs:Z1); works, because the \raisebox moves the tikzmark itself on the page, like it would the letter x for example.

Putting a \raisebox in the \noalign didn't work, but a slightly roundabout way could be to do this:

output of code

\documentclass{article}
\usepackage{tikz,array}

\usetikzlibrary{tikzmark}

\begin{document}

\renewcommand{\arraystretch}{1.2}

\begin{tabular}{|c|}\noalign{\tikzmark{top}}\hline
\raisebox{5pt}{\tikzmark{baseline}}foo
\end{tabular}

\begin{tikzpicture}[overlay,remember picture]
    % if you want to use the same coordinate multiple times
    % it makes sense to define a named \coordinate
    \coordinate (foo) at ({pic cs:top} |- {pic cs:baseline});

    \fill[orange] (foo) circle[radius=.5pt];
\end{tikzpicture}

% foo can of course be used in other tikzpictures as well
\tikz[remember picture,overlay]
   \draw [->] (foo) -- ++(1cm,1cm);

\end{document}

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.