在类似 \raisebox 的环境中换行 + 表格单元格的高度一致

在类似 \raisebox 的环境中换行 + 表格单元格的高度一致

在 Frank Mittelbach 的回答中这里,他构造了一个环境来在\raisebox类似环境中添加换行符。

在 Alain Matthes 的回答中这里中,他展示了如何在表格中获得一致的行高。

问题

我想将这两个答案结合起来,\raisebox同时获得一个类似于 的环境,其中行高在整个表中保持一致。

我怎么做?

更新

以下是 Frank 代码的一个例子:

\documentclass[
  a4paper,
  12pt,
  danish
]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[
  hmargin = 1cm,
  vmargin = 1.5cm
]{geometry}
\usepackage{ragged2e,array}
\usepackage{microtype}


% we need space, -, and newline active and set to some commands
{\obeyspaces
\catcode`\^^M\active%
\catcode`\-\active%
\gdef\setraisedtextactivedef#1#2{\let =#1\let^^M=#1\let-=#2}}

\newbox\raisedtextbox

% main action is to collect material into a box
\def\collectraisedtext{\setbox\raisedtextbox\hbox\bgroup\raisedtextstyle
\gobbleactivespaces}

% and if we want we can use a special style
\def\raisedtextstyle{\textnormal}

% at a space end collection, typeset and restart
\def\raisedtextspace{\egroup
      \X{\box\raisedtextbox}%
      \space
      \collectraisedtext
}

% at \- end colloection, typeset, add discretionary and restart
\def\raisedtextbreak{\egroup\X{\box\raisedtextbox}\discretionary{\X-}{}{}\collectraisedtext}
% at - (explicit hyphen) more or less the same
\def\raisedtexthyphen{\egroup\X{\box\raisedtextbox}\discretionary{\X-}{}{\X-}\collectraisedtext}

% several active spaces (or newlines) would do harm ...
\def\gobbleactivespaces{\futurelet\next\gobbleactivespacesX}
\def\gobbleactivespacesX{%
           \ifx\next\raisedtextspace
               \expandafter\gobbleactivespacesXX
           \fi
}
\def\gobbleactivespacesXX#1{\gobbleactivespaces}

% putting all together
\newenvironment{raisedtext}[1][-0.75ex]
  {%
    \def\X##1{\raisebox{#1}{##1}}%
    \obeyspaces
    \catcode`\^^M\active
    \catcode`\-\active
    \setraisedtextactivedef\raisedtextspace\raisedtexthyphen
    \let\-\raisedtextbreak
    \collectraisedtext
}{%
% at end environment, end collection and typeset (if not empty). 
% Otherwise remove space already inserted before that collection
    \egroup
    \ifdim\wd\raisedtextbox>0pt  % weak prove that this is not empty
      \X{\box\raisedtextbox}%
    \else
      \unskip
    \fi
}


\DisableLigatures[f]{encoding = T1}

\pagestyle{empty}


\begin{document}

\bfseries
\begin{tabular}{
  *{4}{|>{\RaggedRight\arraybackslash}m{0.2\textwidth}}|
}
  \hline
    Konventionelt landbrug
  & Landbrug, hvor det er tilladt at bruge sprøjtegifte og kunstgøding
  & Økologisk landbrug
  & \begin{raisedtext}
      Landbrug, der drives med bedre forhold for dyrene og uden brug af sprøjtegifte og kunstgødning på markerne
    \end{raisedtext} \\[1.5ex]
  \hline
    Kunstgødning
  & Gødning, der er fremstillet på en fabrik
  & Gylle
  & \begin{raisedtext}
      Urin og afføring fra husdyr, der er flydende
    \end{raisedtext} \\[1.5ex]
  \hline
\end{tabular}

\end{document}

输出

我如何(自动)获得此表的均匀行高?

答案1

这些功能彼此之间没有连接,您只需要在列\raisebox中使用即可C

在这里我使用了一个稍微修改过的C列,可以在保持行为不变的情况下更好地增加高度\vcenter

在此处输入图片描述

\documentclass[
  a4paper,
  12pt,
  danish
]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[
  hmargin = 1cm,
  vmargin = 1.5cm
]{geometry}
\usepackage{ragged2e,array}
\usepackage{microtype}

\makeatletter
\newcolumntype{C}[1]{%
 >{\vrule width 0pt height 5\normalbaselineskip
          depth 5\normalbaselineskip
          $\vcenter\@startpbox{#1}\vfill}c<{\vfill\@endpbox $}}
\makeatother

% we need space, -, and newline active and set to some commands
{\obeyspaces
\catcode`\^^M\active%
\catcode`\-\active%
\gdef\setraisedtextactivedef#1#2{\let =#1\let^^M=#1\let-=#2}}

\newbox\raisedtextbox

% main action is to collect material into a box
\def\collectraisedtext{\setbox\raisedtextbox\hbox\bgroup\raisedtextstyle
\gobbleactivespaces}

% and if we want we can use a special style
\def\raisedtextstyle{\textnormal}

% at a space end collection, typeset and restart
\def\raisedtextspace{\egroup
      \X{\box\raisedtextbox}%
      \space
      \collectraisedtext
}

% at \- end colloection, typeset, add discretionary and restart
\def\raisedtextbreak{\egroup\X{\box\raisedtextbox}\discretionary{\X-}{}{}\collectraisedtext}
% at - (explicit hyphen) more or less the same
\def\raisedtexthyphen{\egroup\X{\box\raisedtextbox}\discretionary{\X-}{}{\X-}\collectraisedtext}

% several active spaces (or newlines) would do harm ...
\def\gobbleactivespaces{\futurelet\next\gobbleactivespacesX}
\def\gobbleactivespacesX{%
           \ifx\next\raisedtextspace
               \expandafter\gobbleactivespacesXX
           \fi
}
\def\gobbleactivespacesXX#1{\gobbleactivespaces}

% putting all together
\newenvironment{raisedtext}[1][-0.75ex]
  {%
    \def\X##1{\raisebox{#1}{##1}}%
    \obeyspaces
    \catcode`\^^M\active
    \catcode`\-\active
    \setraisedtextactivedef\raisedtextspace\raisedtexthyphen
    \let\-\raisedtextbreak
    \collectraisedtext
}{%
% at end environment, end collection and typeset (if not empty). 
% Otherwise remove space already inserted before that collection
    \egroup
    \ifdim\wd\raisedtextbox>0pt  % weak prove that this is not empty
      \X{\box\raisedtextbox}%
    \else
      \unskip
    \fi
}


\DisableLigatures[f]{encoding = T1}

\pagestyle{empty}


\begin{document}

\bfseries
\begin{tabular}{
  *{4}{|>{\RaggedRight\arraybackslash}C{0.2\textwidth}}|
}
  \hline
    Konventionelt landbrug
  & Landbrug, hvor det er tilladt at bruge sprøjtegifte og kunstgøding
  & Økologisk landbrug
  & \begin{raisedtext}
      Landbrug, der drives med bedre forhold for dyrene og uden brug af sprøjtegifte og kunstgødning på markerne
    \end{raisedtext} \\[1.5ex]
  \hline
    Kunstgødning
  & Gødning, der er fremstillet på en fabrik
  & Gylle
  & \begin{raisedtext}
      Urin og afføring fra husdyr, der er flydende
    \end{raisedtext} \\[1.5ex]
  \hline
\end{tabular}

\end{document}

答案2

您可以尝试以下代码,例如:

\def\etab#1{\dimen0=0pt \etabA #1; \vbox{\hrule\etabB #1;;;;}}
\def\etabA #1;{\setbox0=\vbox{\kern10pt\etabD#1}%
   \expandafter\ifx\expandafter;\nexttok#1;\else
   \ifdim\dimen0<\ht0 \dimen0=\ht0 \fi
   \expandafter\etabA\fi}
\def\etabB#1;#2;#3;#4;{%
   \expandafter\ifx\expandafter;\nexttok#4;\else 
   \hbox{\vrule\etabC{#1}\etabC{#2}\etabC{#3}\etabC{#4}}\hrule
   \expandafter\etabB\fi}
\def\etabC#1{\vbox to\dimen0{\vss\vbox{\etabD#1}\vss}\vrule} 
\def\etabD{\hsize=3.5cm \leftskip=5pt \rightskip=5pt plus 1cm
   \noindent\ignorespaces}
\def\nexttok#1{#1}

\etab{
    Konventionelt landbrug ;
    Landbrug, hvor det er tilladt at bruge sprøjtegifte og kunstgøding ;
    Økologisk landbrug ;
    Landbrug, der drives med bedre forhold for dyrene og uden brug af
    sprøjtegifte og kunstgødning på markerne ;
    Kunstgødning ;
    Gødning, der er fremstillet på en fabrik ;
    Gylle ;
    Urin og afføring fra husdyr, der er flydende ;
}

\bye

这个想法基于对数据的两次传递。首先,我们测量的最大高度\vbox,然后第二次传递将其用作\dimen0

相关内容