1

I have a defined a NiceTabular which is later on overlayered by tikz to be eventually inserted in a table environment. The MWE is presented below.

\documentclass{article}
\usepackage{nicematrix,booktabs,tikz}

\begin{document}

\begin{NiceTabular}{c|c|c|c}[name=R]
    \hline
    F & R1  & R2 & R3\\
    \hline
    40  & 2.033 & 2.033 & 2.033 \\
    1e3 & 2.033 & 2.033 & 2.034 \\
    1e4 & 2.036 & 2.070 & 2.179 \\
    1e5 & 3.700 & 3.738 & 5.756 \\
    1e6 & 10.31 & 11.40 & 21.57 \\
    1e7 & 31.14 & 38.17 & 78.99 \\
    \hline
\end{NiceTabular}

\begin{table}
    \caption{Comparing values.}
    \label{tab:compareR}
    \centering
    \begin{tikzpicture}[remember picture,overlay]
    \draw[orange,very thick,dashed](R-2-2.north west) -| (R-2-3.north east)-- (R-7-3.south east)-|(R-7-2.south west)--(R-2-2.north west);
    \end{tikzpicture}   
\end{table} 

\end{document}

I cannot seem to figure out how to force the caption to be on top of the tabular. Actually once inserted in my document, the caption is in page (n-1) - text inserted- then table in page (n)...

What am I doing wrong?

3
  • 2
    As you wrote it, the NiceTabular has nothing to do with the table environment. It will placed where it is written. Place the NiceTabular inside the table environment and it will float with it (with the caption in relation to the NiceTabular). Sep 20 at 13:57
  • 1
    why have you placed the (Nice)Tabular at a fixed point in the main document flow but the caption and tikz in a float to appear at a different point in the document? How do you intend that to appear? I would place the tabular under the caption, in the float Sep 20 at 13:57
  • My bad! Thank you @Qrrbrbirlbel
    – Wallflower
    Sep 20 at 14:05

2 Answers 2

2

As said in comments and answers, the {NiceTabular} should be put in the {table}. I post this answer to show how to simplify the Tikz code (a Tikz instruction with rectangle is enough).

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

\begin{document}
\begin{table}
\centering
\caption{Comparing values.}
\label{tab:compareR}
\begin{NiceTabular}{c|c|c|c}
    \hline
    F & R1  & R2 & R3\\
    \hline
    40  & 2.033 & 2.033 & 2.033 \\
    1e3 & 2.033 & 2.033 & 2.034 \\
    1e4 & 2.036 & 2.070 & 2.179 \\
    1e5 & 3.700 & 3.738 & 5.756 \\
    1e6 & 10.31 & 11.40 & 21.57 \\
    1e7 & 31.14 & 38.17 & 78.99 \\
    \hline
    \CodeAfter
    \tikz \draw [orange,very thick,dashed]
        (2-2.north west) rectangle (7-3.south east) ;
\end{NiceTabular}
\end{table} 

\end{document}

Output of the above code

1

As @Qrrbrbirlbel has already pointed out in a comment, you need to place the NiceTabular environment inside the table environment -- and after the \caption statement.

enter image description here

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

\begin{document}
\begin{table}
\centering
\caption{Comparing values.}
\label{tab:compareR}
\begin{NiceTabular}{c|c|c|c}[name=R]
    \hline
    F & R1  & R2 & R3\\
    \hline
    40  & 2.033 & 2.033 & 2.033 \\
    1e3 & 2.033 & 2.033 & 2.034 \\
    1e4 & 2.036 & 2.070 & 2.179 \\
    1e5 & 3.700 & 3.738 & 5.756 \\
    1e6 & 10.31 & 11.40 & 21.57 \\
    1e7 & 31.14 & 38.17 & 78.99 \\
    \hline
\end{NiceTabular}

\begin{tikzpicture}[remember picture,overlay]
\draw[orange,very thick,dashed]
    (R-2-2.north west) -| 
    (R-2-3.north east)-- 
    (R-7-3.south east)-|
    (R-7-2.south west)--
    (R-2-2.north west);
\end{tikzpicture}   
\end{table} 

\end{document}
1
  • 1
    Done. Thank you!
    – Wallflower
    Sep 20 at 14:04

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.