垂直对齐表格顶部的文本*-[t] 被忽略

垂直对齐表格顶部的文本*-[t] 被忽略

我正在使用(注意星号!)设置一个小的表格环境tabular*,它应该用作列表项。我的问题是,[t]我传递给的选项tabular*被忽略,第二列中的文本在垂直方向上保持居中对齐。

结果如下 --- 请注意,第二列中的第二项文本“also short”相对于左列中的文本居中,但我希望它在顶部对齐: 居中对齐的第二列

我的最小代码示例如下所示。相关命令是\mytab我从中获取了列类型的定义这个 tex.stackexchange 答案

\documentclass[a4paper,11pt]{article}
\usepackage[empty]{fullpage}

\setlength{\tabcolsep}{0pt}

\setlength{\marginparwidth}{0pt}

% Adjust margins --- this is really ugly
\addtolength{\oddsidemargin}{-0.5in}
\addtolength{\evensidemargin}{-0.5in}
\addtolength{\textwidth}{1.0in}
\addtolength{\topmargin}{-0.5in}
\addtolength{\textheight}{1.0in}

\newlength{\mytablen}
\setlength{\mytablen}{\textwidth}
%\addtolength{\ressubheadingwidth}{-0.7em}


\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

%-----------------------------------------------------------
\newcommand{\mytab}[4]{
  \begin{tabular*}{\mytablen}[t]{L{13cm}@{\extracolsep{\fill}}R{5cm}}
    \hline
    \textbf{#1} & #2 \\
    \hline
    \textit{#3} & \textit{#4}\\
    \hline
  \end{tabular*}
}

\begin{document}

\begin{list}{}{\setlength{\leftmargin}{0.6em}\setlength{\topsep}{0.0em}\setlength{\itemsep}{-0.2em}}
\item
  \mytab{Just a single line --- nothing fancy}{Short}
  {A short name --- with some text}{20xx}
\item
  \mytab{Significantly longer title --- will have to be broken into the second line and happily continue there}{Also short}
  {A short name --- with some text}{20xx}
\item
  \mytab{Significantly longer title --- will have to be broken into the second line and (un?)happily continue there}{A pretty long title or name, which will be split.}
  {Here are, going to be, lots and lots, of names}{20xx}
\end{list} %}}}

\end{document}

答案1

在声明新的列类型时,必须使用p说明符:m

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

[t]那么环境中就没有必要了tabular*

梅威瑟:

\documentclass[a4paper,11pt]{article}
\usepackage[empty]{fullpage}

\setlength{\tabcolsep}{0pt}

\setlength{\marginparwidth}{0pt}

% Adjust margins --- this is really ugly
\addtolength{\oddsidemargin}{-0.5in}
\addtolength{\evensidemargin}{-0.5in}
\addtolength{\textwidth}{1.0in}
\addtolength{\topmargin}{-0.5in}
\addtolength{\textheight}{1.0in}

\newlength{\mytablen}
\setlength{\mytablen}{\textwidth}
%\addtolength{\ressubheadingwidth}{-0.7em}


\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

%-----------------------------------------------------------
\newcommand{\mytab}[4]{
  \begin{tabular*}{\mytablen}{L{13cm}@{\extracolsep{\fill}}R{5cm}}
    \hline
    \textbf{#1} & #2 \\
    \hline
    \textit{#3} & \textit{#4}\\
    \hline
  \end{tabular*}
}

\begin{document}

\begin{list}{}{\setlength{\leftmargin}{0.6em}\setlength{\topsep}{0.0em}\setlength{\itemsep}{-0.2em}}
\item
  \mytab{Just a single line --- nothing fancy}{Short}
  {A short name --- with some text}{20xx}
\item
  \mytab{Significantly longer title --- will have to be broken into the second line and happily continue there}{Also short}
  {A short name --- with some text}{20xx}
\item
  \mytab{Significantly longer title --- will have to be broken into the second line and (un?)happily continue there}{A pretty long title or name, which will be split.}
  {Here are, going to be, lots and lots, of names}{20xx}
\end{list} %}}}

\end{document} 

输出

在此处输入图片描述

相关内容