表格标题的垂直对齐问题

表格标题的垂直对齐问题

我真的陷入困境,任何建议我都会很感激。我需要为技术报告设计一个标题,如下所示:

标题

第一列宽 2.5 厘米,第二列宽 11 厘米,第三列宽 1 厘米,第四列宽 1 厘米。第一行高 1.3 厘米,第二行高 1 厘米。我需要标题有这个尺寸,因为有些人使用 Open Office,有些人使用 LaTex。

到目前为止,我的 MWE 如下所示:

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage[hmargin=2cm,top=4cm,headheight=6cm,footskip=65pt]{geometry}
\usepackage[version=4]{mhchem} % loads some package that allows to use "\arrayrulewidth"
\usepackage{lipsum}
    
% new columns definition
\newcolumntype{M}[1]{@{}>{\centering\arraybackslash}m{#1}@{}}
\newcolumntype{N}{@{}m{0pt}@{}}
                
\pagestyle{fancy}
\renewcommand\headrulewidth{0pt} % no line between document and header
\fancyhf{} % clear header and footer
\fancyhead[C]{%
    \begin{tabular}{|M{2.5cm-1.25\arrayrulewidth}|M{11cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|N}
        \hline
        \multirow{2}{*}{\includegraphics[height=2.2cm,width=2.2cm]{example-image}} & \makecell{Report \\ \footnotesize{from a research center}} & \multicolumn{2}{M{2cm-1.5\arrayrulewidth}|}{\makecell{Deliverable\\ 2.0}} & \rule{0pt}{1.3cm}\\
        \cline{2-4} 
        & \multicolumn{2}{M{12cm-1.5\arrayrulewidth}|}{\makecell{Report title \\ and number}}     & \makecell{Page \\ \thepage} & \rule{0pt}{1cm}\\
        \hline
    \end{tabular}
}

\begin{document}

\section{Section title}
%% add this if you want the fancy style also on the first page of a chapter:
\thispagestyle{fancy}
\subsection{Subsection title}
\lipsum[1-10]

\end{document}

在此处输入图片描述

问题是左侧单元格中的图像是方形的,我不知道如何将其放在中间(垂直对齐)。如果您能提供任何意见,我将不胜感激。

其他单元格存在垂直对齐问题,因为它们似乎位于单元格中心下方。但它并不像左侧单元格中的图像那么麻烦。

答案1

解决主要问题的一个方法是使用minipage将图像放置在表格单元格内,居中并占据单元格的整个宽度。然后,您可以使用调整其垂直对齐方式。您可以更改在单元格中上下移动图像的at\vspace数量。-0.8\vspace{-0.8\baselineskip}

然后你会得到类似这样的结果:

在此处输入图片描述

完整代码

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage[hmargin=2cm,top=4cm,headheight=6cm,footskip=65pt]{geometry}
\usepackage[version=4]{mhchem} % loads some package that allows to use "\arrayrulewidth"
\usepackage{lipsum}

% new columns definition
\newcolumntype{M}[1]{@{}>{\centering\arraybackslash}m{#1}@{}}
\newcolumntype{N}{@{}m{0pt}@{}}

\pagestyle{fancy}
\renewcommand\headrulewidth{0pt} % no line between document and header
\fancyhf{} % clear header and footer
\fancyhead[C]{%
    \begin{tabular}{|M{2.5cm-1.25\arrayrulewidth}|M{11cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|N}
        \hline
        \multirow{2}{*}{\begin{minipage}{1\linewidth}
                \centering
                \vspace{-0.8\baselineskip}
                \includegraphics[height=2.2cm,width=2.2cm]{example-image}
                \end{minipage}}
                & \makecell{Report \\ \footnotesize{from a research center}} & \multicolumn{2}{M{2cm-1.5\arrayrulewidth}|}{\makecell{Deliverable\\ 2.0}} & \rule{0pt}{1.3cm}\\
        \cline{2-4} 
        & \multicolumn{2}{M{12cm-1.5\arrayrulewidth}|}{\makecell{Report title \\ and number}}     & \makecell{Page \\ \thepage} & \rule{0pt}{1cm}\\
        \hline
    \end{tabular}
}

\begin{document}
    
    \section{Section title}
    %% add this if you want the fancy style also on the first page of a chapter:
    \thispagestyle{fancy}
    \subsection{Subsection title}
    \lipsum[1-10]
    
\end{document}

答案2

像这样?

在此处输入图片描述

\documentclass[a4paper,10pt]{article}
\usepackage[hmargin=2cm,top=4cm,headheight=6cm,footskip=65pt]{geometry}
\usepackage{graphicx}
\usepackage{array, makecell, multirow}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear header and footer
\renewcommand\headrulewidth{0pt} % no line between document and header
\fancyhead[C]{\centering%
    \begin{tabular}{|P{25mm}|c |P{1cm}|P{1cm}|@{}c@{}}
        \hline
\multirow{5}{=}[4.4mm]{\centering\includegraphics[height=22mm, width=22mm]{example-image}}
    &   \multicolumn{1}{P{110mm}|}{\makecell{\fontsize{18pt}{20pt}\selectfont\textbf{Report}\\
                                           \large  from a research center}}
            & \multicolumn{2}{P{20mm}|}%
                          {\makecell{Deliverable\\   2.0}}
                            & \rule[-5mm]{0pt}{13mm}\\
    \cline{2-5}
    &   \multicolumn{2}{P{120mm}|}%
                    {\makecell{Report title\\    and number}}
            &   Page\newline
                \thepage    & \rule[-5mm]{0pt}{10mm}\\
    \hline
    \end{tabular}
}

\usepackage{lipsum}
\usepackage{hyperref} % had to be last in preamble

\begin{document}

\section{Section title}
\thispagestyle{fancy}
\subsection{Subsection title}
\lipsum\lipsum

\end{document}

答案3

另一种变体,使用\multirowcell并考虑到 multirow 的 number 参数不是行数,而是线,这不一定相同。此外,您的单元格很不寻常,因为它们包含不可见的规则以确保固定高度。所以我将多行放在第二行,并使用负的十进制数参数。

无关hyperref应作为最后一个包加载,只有极少数例外。

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage[hmargin=2cm,top=4cm,headheight=6cm,footskip=65pt]{geometry}
\usepackage[version=4]{mhchem} % loads some package that allows to use "\arrayrulewidth"
\usepackage{lipsum}

% new columns definition
\newcolumntype{M}[1]{@{}>{\centering\arraybackslash}m{#1}@{}}
\newcolumntype{N}{@{}m{0pt}@{}}

\pagestyle{fancy}
\renewcommand\headrulewidth{0pt} % no line between document and header
\fancyhf{} % clear header and footer
\fancyhead[C]{%
    \begin{tabular}{|M{2.5cm-1.25\arrayrulewidth}|M{11cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|N}
        \hline& \makecell{Report \\ \footnotesize{from a research center}} & \multicolumn{2}{M{2cm-1.5\arrayrulewidth}|}{\makecell{Deliverable\\ 2.0}} & \rule{0pt}{1.3cm}\\
        \cline{2-4}
        \multirowcell{-4.8}{\includegraphics[height=2.2cm,width=2.2cm]{example-image}}
        & \multicolumn{2}{M{12cm-1.5\arrayrulewidth}|}{\makecell{Report title \\ and number}} & \makecell{Page \\ \thepage} & \rule{0pt}{1cm}\\
        \hline
    \end{tabular}
}

\begin{document}

\section{Section title}
%% add this if you want the fancy style also on the first page of a chapter:
\thispagestyle{fancy}
\subsection{Subsection title}
\lipsum[1-10]

\end{document} 

在此处输入图片描述

相关内容