横向表格,文本换行

横向表格,文本换行

我有

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{colortbl}
\usepackage{array, makecell, caption}
\definecolor{gray1}{RGB}{238,236,225}
\definecolor{gray2}{RGB}{224,224,224}
\definecolor{oran1}{RGB}{255,192,0}
\definecolor{yelw1}{RGB}{255,227,111}
\definecolor{blue1}{RGB}{197,217,241}
\definecolor{gree1}{RGB}{196,215,155}
\definecolor{crea1}{RGB}{252,245,238}
\definecolor{pink1}{RGB}{218,150,148}

\usepackage{tabulary}

\newcommand{\Poor}{\cellcolor{oran1} Poor}
\newcommand{\Fair}{\cellcolor{yelw1} Fair}
\newcommand{\Excellent}{\cellcolor{gree1} Excellent}
\newcommand{\Good}[1]{\cellcolor{blue1} Good #1}

\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
\begin{center}
  \begin{tabulary}{0.9\textwidth}{LRRRRRRR}
    \rowcolor{gray1}
                  & Matlab  & SciPy  & deSolve & DifferentialEquations.jl & Sundials & Hairer &
    ODEPACK / Netlib / NAG \\
    \rowcolor{gray1}
    Language      & Matlab  & Python & R       & Julia                    & C++ and Fortran & Fortran &
    Fortran \\
    \hline
    Selection of Methods for ODEs & \Fair & \Poor & \Poor & \Excellent &
    \Good{(including ARKCODE)} & \Good & \Good \\
    Efficiency\footnote{whatever} & \Poor & \Poor & \Poor & \Excellent &
    \Good{(including ARKCODE)} & \Good & \Good \\
  \end{tabulary}  
\end{center}
\end{sidewaystable}

\end{document} 

为什么 Python 变成了 Pytho,deSolveR 被挤压了,为什么我指定了一个脚注却得到了两个脚注?

输出

答案1

似乎tabulary使用了两次其内容,因此打印了两个脚注而不是一个。解决方案是将以下内容添加到您的序言中:

\newcounter{mucounter}
\def\myuseonce#1{\ifnum\value{mucounter}=0\stepcounter{mucounter}\else#1\setcounter{mucounter}{0}\fi}

并使用脚注如下:

\myuseonce{\footnote{Something}}

我发现的第二个问题是您使用过但至少在 MWE 中\textwidth需要。\textheight

另外,我并不经常使用tabulary,但您必须设置最小宽度,以使标题使用“良好”宽度中断。这可以通过设置 \tymin 长度来实现。

代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{colortbl}
\usepackage{array, makecell, caption}
\definecolor{gray1}{RGB}{238,236,225}
\definecolor{gray2}{RGB}{224,224,224}
\definecolor{oran1}{RGB}{255,192,0}
\definecolor{yelw1}{RGB}{255,227,111}
\definecolor{blue1}{RGB}{197,217,241}
\definecolor{gree1}{RGB}{196,215,155}
\definecolor{crea1}{RGB}{252,245,238}
\definecolor{pink1}{RGB}{218,150,148}

\usepackage{tabulary}

\newcommand{\Poor}{\cellcolor{oran1} Poor}
\newcommand{\Fair}{\cellcolor{yelw1} Fair}
\newcommand{\Excellent}{\cellcolor{gree1} Excellent}
\newcommand{\Good}[1]{\cellcolor{blue1} Good #1}

\usepackage{rotating}

%ADDED for the footnote problem
\newcounter{mucounter}
\def\myuseonce#1{\ifnum\value{mucounter}<1\stepcounter{mucounter}\else#1\setcounter{mucounter}{0}\fi}

\begin{document}


\begin{sidewaystable}
  \centering
  %Selected the minimum text to adjust the minimum tcell width
  \settowidth\tymin{Equations}
  \begin{tabulary}{0.9\textwidth}{m{3.6cm}RRRRRRR}
    \rowcolor{gray1}
                  & Matlab  & SciPy  & deSolveR & Differential\-Equations.jl & Sundials & Hairer &
    ODEPACK / Netlib / NAG \\
    \rowcolor{gray1}
    Language      & Matlab  & Python & R       & Julia                    & \mbox{C++ and} \mbox{Fortran} & Fortran &
    Fortran \\
    \hline
    Selection of Methods for ODEs & \Fair & \Poor & \Poor & \Excellent &
    \Good{(including ARKCODE)} & \Good & \Good \\
    Efficiency\myuseonce{\footnote{whatever}} & \Poor & \Poor & \Poor & \Excellent &
    \Good{(including ARKCODE)} & \Good & \Good \\
  \end{tabulary}  
\end{sidewaystable}
\end{document}

输出:

在此处输入图片描述

PS:如果你已经在实际代码中旋转了 pdf 页面,请忽略\textheight(使其成为现实)\textwidth

答案2

一些评论和意见:

  • 有些列不需要任何自动换行;我建议您r对它们使用基本样式。

  • 通过书写 告知 LaTeX 哪里可以允许换行Differential\-Equations.jl

  • 使用threeparttable环境生成对齐良好的表格脚注。

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{array, caption}
\usepackage[flushleft]{threeparttable}
\renewcommand\TPTtagStyle{\textit}

\definecolor{gray1}{RGB}{238,236,225}
\definecolor{gray2}{RGB}{224,224,224}
\definecolor{oran1}{RGB}{255,192,0}
\definecolor{yelw1}{RGB}{255,227,111}
\definecolor{blue1}{RGB}{197,217,241}
\definecolor{gree1}{RGB}{196,215,155}
\definecolor{crea1}{RGB}{252,245,238}
\definecolor{pink1}{RGB}{218,150,148}

\usepackage{tabularx,ragged2e}
\newcolumntype{R}{>{\RaggedLeft\arraybackslash\hspace{0pt}}X}
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}

\newcommand{\Poor}{\cellcolor{oran1} Poor}
\newcommand{\Fair}{\cellcolor{yelw1} Fair}
\newcommand{\Excellent}{\cellcolor{gree1} Excellent}
\newcommand{\Good}[1]{\cellcolor{blue1} Good #1}

\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
\setlength\extrarowheight{3pt}
\centering
\begin{threeparttable}
  \begin{tabularx}{0.9\textwidth}{LrrrRRrR}
  \hline
    \rowcolor{gray1}
    & Matlab  & SciPy  & deSolve 
    & Differential\-Equations.jl 
    & Sundials & Hairer 
    & ODEPACK\slash Netlib\slash NAG \\
    \rowcolor{gray1}
    Language & Matlab  & Python & R & Julia  
    & C++ and Fortran & Fortran & Fortran \\
    %\hline
    Selection of Methods for ODEs & \Fair & \Poor & \Poor & \Excellent &
    \Good{(incl. ARKCODE)} & \Good & \Good \\
    Efficiency\tnote{a} & \Poor & \Poor & \Poor & \Excellent &
    \Good{(incl. ARKCODE)} & \Good & \Good \\
  \hline
  \end{tabularx}  

  \medskip
  \begin{tablenotes}
  \item[a] Whatever.
  \end{tablenotes}
  \end{threeparttable}
\end{sidewaystable}

\end{document} 

附录:不要将 7 个数据列的内容设置为右对齐(如您的代码和上面的答案中所做的那样),而是将列居中排版可能会更好。

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{array, caption}
\usepackage[flushleft]{threeparttable}
\renewcommand\TPTtagStyle{\textit}

\definecolor{gray1}{RGB}{238,236,225}
\definecolor{gray2}{RGB}{224,224,224}
\definecolor{oran1}{RGB}{255,192,0}
\definecolor{yelw1}{RGB}{255,227,111}
\definecolor{blue1}{RGB}{197,217,241}
\definecolor{gree1}{RGB}{196,215,155}
\definecolor{crea1}{RGB}{252,245,238}
\definecolor{pink1}{RGB}{218,150,148}

\usepackage{tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash%
    \hspace{0pt}\hsize=0.9\hsize}X}
\newcolumntype{L}{>{\RaggedRight\arraybackslash%
    \hspace{0pt}\hsize=1.3\hsize}X}


\newcommand{\Poor}{\cellcolor{oran1} Poor}
\newcommand{\Fair}{\cellcolor{yelw1} Fair}
\newcommand{\Excellent}{\cellcolor{gree1} Excellent}
\newcommand{\Good}[1]{\cellcolor{blue1} Good #1}

\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
\setlength\extrarowheight{3pt}
\setlength\tabcolsep{4pt}
\centering
\begin{threeparttable}
\begin{tabularx}{0.9\textwidth}{ L cccCCcC }
    \hline
    \rowcolor{gray1}
    & Matlab  & SciPy  & deSolve & Differential\-Equations.jl 
    & Sundials & Hairer & ODEPACK\slash Netlib\slash NAG \\
    \rowcolor{gray1}
    Language & Matlab  & Python & R & Julia  
             & C++ and Fortran & Fortran & Fortran \\
    %\hline
    Selection of Methods for ODEs 
         & \Fair & \Poor & \Poor & \Excellent 
         & \Good{(incl. ARKCODE)} & \Good & \Good \\
    Efficiency\tnote{a} 
         & \Poor & \Poor & \Poor & \Excellent 
         & \Good{(incl. ARKCODE)} & \Good & \Good \\
   \hline
\end{tabularx}  

\smallskip
\begin{tablenotes}
  \item[a] Whatever.
\end{tablenotes}
\end{threeparttable}
\end{sidewaystable}

\end{document} 

相关内容