将内容置于与侧边标题相邻的单元格的中心

将内容置于与侧边标题相邻的单元格的中心

我有一张由以下代码生成的表格:

\documentclass[a4paper]{article}
\usepackage{tabularx}
\usepackage{rotating}

\begin{document}

\begin{table}[ht]

\begin{center}
\begin{tabularx}{\textwidth}{|l|X|l|l|l|l|l|l|}
\hline
Item    &   Task    & 
\multicolumn{1}{|c|}{
\begin{sideways}
Resident Engineer \,
\end{sideways}} &
\multicolumn{1}{c|}{
\begin{sideways}
Pavement Engineer \,
\end{sideways}} &

\multicolumn{1}{c|}{
\begin{sideways}
Surveyor \,
\end{sideways}} &
\multicolumn{1}{c|}{
\begin{sideways}
Environmental Specialist \,
\end{sideways}} &
\multicolumn{1}{c|}{
\begin{sideways}
Materials Technicians \,
\end{sideways}} &
\multicolumn{1}{c|}{
\begin{sideways}
Inspectors of Works \,
\end{sideways}} \\
\hline
Task 1  &   Mobilization and Project Inception & P  & P & P &  P    & P & P     \\
\hline
Task 2  &   Carry out data collection \& review of existing data  & P& S    & P &P  &P  & P\\
\hline
Task 3  &   Compiling and submitting the Inception report  &P   &   S&  &   &P  &       \\
\hline

\end{tabularx}
\end{center}

\end{table}


\end{document}

问题是物品任务单元格未居中。如何将文本置于这两个单元格的中央(垂直和水平对齐)?

答案1

由于您知道“最长”条目的内容,因此您可以利用这一点,并相应地提高前两个标题条目的内容。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{graphicx}% http://ctan.org/pkg/graphicx

\begin{document}

\begin{table}[ht]
  \newlength{\tabheadheight}
  \settoheight{\tabheadheight}{\rotatebox{90}{Environmental Specialist\,}}
  \begin{tabularx}{\textwidth}{|c|X|l|l|l|l|l|l|}
    \hline
    \raisebox{\dimexpr.5\tabheadheight-.5\normalbaselineskip}{Item} &
    \centering\raisebox{\dimexpr.5\tabheadheight-.5\normalbaselineskip}{Task} & 
    \rotatebox{90}{Resident Engineer} &
    \rotatebox{90}{Pavement Engineer} &
    \rotatebox{90}{Surveyor} &
    \rotatebox{90}{Environmental Specialist\,} &
    \rotatebox{90}{Materials Technicians} &
    \rotatebox{90}{Inspectors of Works} \\
    \hline
    Task 1  &   Mobilization and Project Inception & P  & P & P &  P    & P & P     \\
    \hline
    Task 2  &   Carry out data collection \& review of existing data  & P& S    & P &P  &P  & P\\
    \hline
    Task 3  &   Compiling and submitting the Inception report  &P   &   S&  &   &P  &       \\
    \hline
  \end{tabularx}
\end{table}

指某东西的用途graphicx足以通过 获得旋转的标题\rotatebox{90}{<stuff>}。此外,使用环境将宽度center居中是没有必要的,因为它适合文本块宽度。tabularx\textwidth

在上面的例子中,长度\tabheadheight用于捕获“最长”条目的高度。随后,前两个标题被提升.5\tabheadheight-.5\normalbaselineskip,并将它们设置为垂直居中。

答案2

在此处输入图片描述

您可以将列对齐方式覆盖为居中,然后目测提高文本(或者您可以测量最长的标题)

\documentclass[a4paper]{article}
\usepackage{tabularx}
\usepackage{rotating}

\begin{document}

\begin{table}[ht]

\begin{center}
\begin{tabularx}{\textwidth}{|l|X|l|l|l|l|l|l|}
\hline
\multicolumn{1}{|c|}{\raisebox{4em}{Item}}  &
\multicolumn{1}{c|}{\raisebox{4em}{Task}}   & 
\multicolumn{1}{|c|}{
\begin{sideways}
Resident Engineer \,
\end{sideways}} &
\multicolumn{1}{c|}{
\begin{sideways}
Pavement Engineer \,
\end{sideways}} &

\multicolumn{1}{c|}{
\begin{sideways}
Surveyor \,
\end{sideways}} &
\multicolumn{1}{c|}{
\begin{sideways}
Environmental Specialist \,
\end{sideways}} &
\multicolumn{1}{c|}{
\begin{sideways}
Materials Technicians \,
\end{sideways}} &
\multicolumn{1}{c|}{
\begin{sideways}
Inspectors of Works \,
\end{sideways}} \\
\hline
Task 1  &   Mobilization and Project Inception & P  & P & P &  P    & P & P     \\
\hline
Task 2  &   Carry out data collection \& review of existing data  & P& S    & P &P  &P  & P\\
\hline
Task 3  &   Compiling and submitting the Inception report  &P   &   S&  &   &P  &       \\
\hline

\end{tabularx}
\end{center}

\end{table}


\end{document}

相关内容