tabularx 中行与行之间为零间距

tabularx 中行与行之间为零间距

假设您在序言中有此代码,用于在 tabularx 环境中将不同大小的图片居中(垂直和水平)(每个单元格中的图片都包含 \includegraphics):

\newcolumntype{C}{>{\centering\arraybackslash}X}

如何才能使行与行之间的空间变为零?

以下是该问题的 MWE:

\usepackage{tikz}
\usepackage{tabularx}
\usetikzlibrary{positioning}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\documentclass[12pt,twoside,openright,demo]{report}

\begin{document}

\begin{figure}[!ht]
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{tabularx}{\textwidth}{@{}CCC@{}}

\begin{tikzpicture}
\node (figure) at (0,0) {\includegraphics[width=0.03]{example-image-a}};
\node[fill=white,draw=black,anchor=north west,below right=0.2cm and 0.2cm of figure.north west] {1};
\end{tikzpicture}

    &
    
\begin{tikzpicture}
\node (figure) at (0,0) {\includegraphics[width=0.03]{example-image-b}};
\node[fill=white,draw=black,anchor=north west,below right=0.2cm and 0.2cm of figure.north west] {2};
\end{tikzpicture}
    
    &

\begin{tikzpicture}
\node (figure) at (0,0) {\includegraphics[width=0.05]{example-image-c}};
\node[fill=white,draw=black,anchor=north west,below right=0.2cm and 0.2cm of figure.north west] {3};
\end{tikzpicture}


    \\


\begin{tikzpicture}
\node (figure) at (0,0) {\includegraphics[width=0.03]{example-image-d}};
\node[fill=white,draw=black,anchor=north west,below right=0.2cm and 0.2cm of figure.north west] {4};
\end{tikzpicture}

    &
    
\begin{tikzpicture}
\node (figure) at (0,0) {\includegraphics[width=0.03]{example-image-e}};
\node[fill=white,draw=black,anchor=north west,below right=0.2cm and 0.2cm of figure.north west] {5};
\end{tikzpicture}
    
    &

\begin{tikzpicture}
\node (figure) at (0,0) {\includegraphics[scale=0.7,width=0.03]{example-image-f}};
\node[fill=white,draw=black,anchor=north west,below right=0.2cm and 0.2cm of figure.north west] {6};
\end{tikzpicture}


\end{tabularx}
\end{figure}\FloatBarrier

\end{document}

答案1

不确定我是否理解了您的格式化目标。可能是类似以下内容?请注意完全没有环境tabularx

在此处输入图片描述

\documentclass[12pt,twoside,openright,demo]{report}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{figure}[!ht]
\begin{tikzpicture}%
\node (figure) at (0,0) {\includegraphics[angle=-90,width=0.31\linewidth]{images/taller_1.jpeg}};%
\node[fill=white,draw=black,anchor=north west,below right=2mm and 2mm of figure.north west]{1};%
\end{tikzpicture}\hfill    
\begin{tikzpicture}%
\node (figure) at (0,0) {\includegraphics[angle=-90,width=0.31\linewidth]{images/taller_2.jpeg}};%
\node[fill=white,draw=black,anchor=north west,below right=2mm and 2mm of figure.north west]{2};%
\end{tikzpicture}\hfill
\begin{tikzpicture}%
\node (figure) at (0,0) {\includegraphics[angle=-90,width=0.31\linewidth]{images/taller_3.jpeg}};%
\node[fill=white,draw=black,anchor=north west,below right=2mm and 2mm of figure.north west]{3};%
\end{tikzpicture}

\begin{tikzpicture}%
\node (figure) at (0,0) {\includegraphics[angle=-90,width=0.31\linewidth]{images/taller_4.jpeg}};%
\node[fill=white,draw=black,anchor=north west,below right=2mm and 2mm of figure.north west]{4};%
\end{tikzpicture}\hfill
\begin{tikzpicture}%
\node (figure) at (0,0) {\includegraphics[angle=-90,width=0.31\linewidth]{images/taller_5.jpeg}};%
\node[fill=white,draw=black,anchor=north west,below right=2mm and 2mm of figure.north west]{5};%
\end{tikzpicture}\hfill
\begin{tikzpicture}%
\node (figure) at (0,0) {\includegraphics[angle=-90,width=0.31\linewidth]{images/taller_6.jpeg}};%
\node[fill=white,draw=black,anchor=north west,below right=2mm and 2mm of figure.north west]{6};%
\end{tikzpicture}
\end{figure}

\end{document}

答案2

太渴望评论了... 至少对我来说,你的问题是什么还不清楚。通过一点点重写,你的 MWE 给出了以下结果:

在此处输入图片描述

\documentclass[12pt,twoside,openright,demo]{report}
\usepackage[export]{adjustbox}
\usepackage{tikz}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usetikzlibrary{positioning}


\begin{document}
    \begin{figure}[!ht]
\renewcommand\tabularxcolumn[1]{m{#1}}
\setkeys{Gin}{angle=-90,width=\linewidth}
\tikzset{
N/.style = {draw, fill=white,anchor=north west,
            below right=0.2cm and 0.2cm of figure.north west}
        }\begin{tabularx}{\textwidth}{@{}CCC@{}}
\hline
\begin{tikzpicture}
\node[draw] (figure) {\includegraphics{images/taller_1.jpeg}};
\node[N] {1};
\end{tikzpicture}
    &
\begin{tikzpicture}
\node[draw] (figure) {\includegraphics{images/taller_2.jpeg}};
\node[N] {2};
\end{tikzpicture}
    &
\begin{tikzpicture}
\node[draw] (figure) {\includegraphics{images/taller_3.jpeg}};
\node[N] {3};
\end{tikzpicture}
 \hline
   \\

\begin{tikzpicture}
\node[draw] (figure) {\includegraphics{images/taller_4.jpeg}};
\node[N] {4};
\end{tikzpicture}
    &
\begin{tikzpicture}
\node[draw] (figure) {\includegraphics{images/taller_5.jpeg}};
\node[N] {5};
\end{tikzpicture}
    &
\begin{tikzpicture}
\node[draw] (figure) {\includegraphics{images/taller_6.jpeg}};
\node[N] {6};
\end{tikzpicture}
\hline
\end{tabularx}
    \end{figure}
\end{document}

第一行图​​像的底部是否应该接触第二行图像的顶部?

编辑: 从您的评论中可以得出结论,您遵循了以下做法:

在此处输入图片描述

这是一个相当不寻常的请求,但可以使用tabularray包相对轻松地完成。其X列选项cm居中单元格的内容分别水平和垂直:

\documentclass[12pt,twoside,openright,demo]{report}
\usepackage[export]{adjustbox}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{tabularray}


\begin{document}
    \begin{figure}[!ht]
\setkeys{Gin}{angle=-90,width=\linewidth}
\tikzset{
M/.style = {inner sep=0pt, outer sep=0pt},
N/.style = {draw, fill=white,anchor=north west,
            below right=0.2cm and 0.2cm of figure.north west}
        }
\begin{tblr}{colspec={@{} *{3}{X[c,m]} @{}},
             rowsep=-4.4pt}   
\begin{tikzpicture}
\node[M] (figure) {\includegraphics{images/taller_1.jpeg}};
\node[N] {1};
\end{tikzpicture}
    &
\begin{tikzpicture}
\node[M] (figure) {\includegraphics{images/taller_2.jpeg}};
\node[N] {2};
\end{tikzpicture}
    &
\begin{tikzpicture}
\node[M] (figure) {\includegraphics{images/taller_3.jpeg}};
\node[N] {3};
\end{tikzpicture}   \\
%    \vspace{-8pt}
\begin{tikzpicture}
\node[M] (figure) {\includegraphics{images/taller_4.jpeg}};
\node[N] {4};
\end{tikzpicture}
    &
\begin{tikzpicture}
\node[M] (figure) {\includegraphics{images/taller_5.jpeg}};
\node[N] {5};
\end{tikzpicture}
    &
\begin{tikzpicture}
\node[M] (figure) {\includegraphics{images/taller_6.jpeg}};
\node[N] {6};
\end{tikzpicture}
\end{tblr}
    \end{figure}
\end{document}

相关内容