我有一个带有 \cline 边框的长表。不幸的是,第二列中的图像没有垂直居中。我甚至无法以任何方式更改垂直位置。我发现了这个类似的问题:相对于长表格段落垂直居中图像
但改变 p 和 m 参数似乎没有影响。
这是我的最小工作示例:
\documentclass[a4paper]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[ngerman,english]{babel}
\usepackage[T1]{fontenc}
\usepackage{mwe}
\usepackage{longtable}
\usepackage{array}
\begin{document}
\begin{longtable}{m{0.06\textwidth}p{0.3\textwidth}m{0.05\textwidth}m{0.05\textwidth}m{0.05\textwidth}m{0.05\textwidth}m{0.05\textwidth}m{0.05\textwidth}}
% \begin{longtable}{p{0.06\textwidth}m{0.3\textwidth}m{0.05\textwidth}m{0.05\textwidth}m{0.05\textwidth}m{0.05\textwidth}m{0.05\textwidth}m{0.05\textwidth}} % doesn't work either
Index & Figure & bla & bla & bla & bla & bla & bla\\
\cline{2-8}
1 & \includegraphics[width=0.2\linewidth]{example-image-a} & bla & bla & bla & bla & bla & bla \\
\cline{2-8}
2 & \includegraphics[width=0.2\linewidth]{example-image-a} & bla & bla & bla & bla & bla & bla \\
\cline{2-8}
3 & \includegraphics[width=0.2\linewidth]{example-image-a} & bla & bla & bla & bla & bla & bla \\
\cline{2-8}
\end{longtable}
\end{document}
输出如下所示:
似乎底部边距较高。如何使图像垂直居中(以及文本,因为文本似乎太低了)?
答案1
我总是建议\cmidrule
从 开始booktabs
,因为它可以增加很好的垂直间距。这里的技巧是将图形稍微降低一点:
\documentclass[a4paper]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman,english]{babel}
\usepackage{longtable}
\usepackage{array}
\usepackage{booktabs}
\usepackage{graphicx}
\newcommand{\lowincludegraphics}[2][]{%
\raisebox{-0.7\dp\strutbox}{\includegraphics[#1]{#2}}%
}
\begin{document}
\begin{longtable}{
c
m{0.3\textwidth}
*{6}{c}
}
Index & Figure & bla & bla & bla & bla & bla & bla\\
\cmidrule{2-8}
1 & \lowincludegraphics[width=0.2\linewidth]{example-image-a} &
bla & bla & bla & bla & bla & bla \\
\cmidrule{2-8}
1 & \lowincludegraphics[width=0.2\linewidth]{example-image-a} &
bla & bla & bla & bla & bla & bla \\
\cmidrule{2-8}
1 & \lowincludegraphics[width=0.2\linewidth]{example-image-a} &
bla & bla & bla & bla & bla & bla \\
\cmidrule{2-8}
\end{longtable}
\end{document}
答案2
m{0.3\textwidth}
这里有一个建议:用替换第二列说明符Sc
,其中S
是包定义的前列说明符cellspace
,它确保最小列中单元格顶部和底部的垂直间距,并加载adjustbox
。如果加载siunitx
,它已经定义了S
列类型,请将其替换S
为C
:
\documentclass[a4paper]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[ngerman,english]{babel}
\usepackage[T1]{fontenc}
\usepackage{mwe}
\usepackage[export]{adjustbox}
\usepackage{longtable}
\usepackage{array}
\usepackage{cellspace, booktabs}
\setlength{\cellspacetoplimit}{3pt}
\setlength{\cellspacebottomlimit}{3pt}
\begin{document}
\begin{longtable}{m{0.06\textwidth}Sc m{0.05\textwidth} *{6}{m{0.05\textwidth}}}
Index & Figure & bla & bla & bla & bla & bla & bla\\
\cline{2-8}
1 & \includegraphics[width=0.2\linewidth, valign = c]{example-image-a} & bla & bla & bla & bla & bla & bla \\
\cline{2-8}
2 & \includegraphics[width=0.2\linewidth, valign = c]{example-image-a} & bla & bla & bla & bla & bla & bla \\
\cline{2-8}
3 & \includegraphics[width=0.2\linewidth, valign = c]{example-image-a} & bla & bla & bla & bla & bla & bla \\
\cline{2-8}
\end{longtable}
\end{document}