Tabu 中的旋转和居中文本

Tabu 中的旋转和居中文本

通过查看此处回答的各种问题,我拼凑了一些可以在禁忌中旋转和居中文本的东西。以下宏做了有趣的部分:

\newcommand{\vertText}[1]{
   \parbox[b]{7mm}{\centering \rotatebox[origin=c]{90}{\parbox[c]{1cm}{\centering \textbf{#1}}}}}

我不喜欢这个解决方案的一点是,它必须在宏中嵌入适当的大小才能使其工作。有没有办法做到这一点,以便自动完成大小调整?

梅威瑟:

\documentclass[10pt]{article}
\usepackage{tabu}
\usepackage{rotating}

\begin{document}

\newcommand{\vertText}[1]{
  \parbox[b]{7mm}{\centering \rotatebox[origin=c]{90}{\parbox[c]{1cm}{\centering \textbf{#1}}}}}

\tabulinesep=1.2mm
\begin{tabu}{|X[-1,cm]|X[2m]|X[2m]|X[2m]|} 
\tabucline[1pt]-
\rowfont[c]{\bfseries} & 5 points
                   & 3 points
                   & 1 point \\ \tabucline[1pt]-
\vertText{Ref. Data}
 & City, State, Month, Day, and Year given.  Data shown with appropriate units.
 & Some information is missing or units are not shown.
 & Significant information missing, incomplete, or incorrect.
 \\ \tabucline[1pt]-
\vertText{Stats.}
 & 5 Number summary, Mean, Standard Deviation, IQR, and Range shown.
   Appropriate units and precision on all numbers.
 & Some numbers missing or incorrect, or units missing or precision
   incorrect on values.
 & Many numbers missing or incorrect.
 \\ \tabucline[1pt]-
\vertText{Histo.}
 & Computer generated histogram with 5 or 6 classes including labels
   and units on the axes, and title.
 & Number of bars incorrect or units or title missing.
 & Histogram has multiple flaws such as missing labels, title, number
    of bars.
 \\ \tabucline[1pt]-
\end{tabu}
\end{document}

答案1

  • 据我所知,没有简单的方法可以自动确定每行第一列文本的可用垂直空间(例如,测量存储单元格内容的框的高度,然后比较它们的高度,然后使用最大值确定旋转文本的长度)
  • 通过使用rothead{...}frommakecell包,可以实现稍微简单的代码,您可以通过该包规定旋转文本的最大长度。

在此处输入图片描述

对于上面的表格也使用了ragged2e包(为了更好地格式化单元格中的文本:

\documentclass[10pt]{article}
\usepackage{ragged2e}                         % <-- added
\usepackage{rotating}
\usepackage{makecell,                         % <-- added
            tabu}
\renewcommand\theadfont{\normalsize\bfseries} % <-- added

\begin{document}

\settowidth\rotheadsize{\theadfont stats.}    % <-- added
\tabulinesep=1.2mm
\begin{tabu}{|c|X[2, Lm]|X[2, Lm]|X[2 Lm]|}   % <-- changed
\tabucline[1pt]-
\rowfont[c]{\bfseries} & 5 points
                   & 3 points
                   & 1 point \\ \tabucline[1pt]-
\rothead{Ref. Data}
 & City, State, Month, Day, and Year given.  Data shown with appropriate units.
 & Some information is missing or units are not shown.
 & Significant information missing, incomplete, or incorrect.
 \\ \tabucline[1pt]-
\rothead{Stats.}
 & 5 Number summary, Mean, Standard Deviation, IQR, and Range shown.
   Appropriate units and precision on all numbers.
 & Some numbers missing or incorrect, or units missing or precision
   incorrect on values.
 & Many numbers missing or incorrect.
 \\ \tabucline[1pt]-
\rothead{Histo.}
 & Computer generated histogram with 5 or 6 classes including labels
   and units on the axes, and title.
 & Number of bars incorrect or units or title missing.
 & Histogram has multiple flaws such as missing labels, title, number
    of bars.
 \\ \tabucline[1pt]-
\end{tabu}
\end{document}

相关内容