0

In Frank Mittelbach's answer here, he constructs an environment to add linebreak in a \raisebox-like environment.

In Alain Matthes' answere here, he shows how to get a consistent row height in a table.

Question

I would like to combine these two answers to get a \raisebox-like environment where the row height is consistent throughout the table, at the same time.

How do I do that?

Update

Here is an example with Frank's code:

\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}

output

How do I (automatically) get an even row height in this table?

  • 1
    You should provide an example input and say what output you want. The two answers are unrelated, you could use them both at the same time but I can not guess what you mean by combining them. One fixes the vertical extent of the area into which text is being typeset, and the other raises the position of some characters within the current line. You could use the raisebox variant in the box constructed with fixed height. – David Carlisle Mar 17 '16 at 9:09
  • @DavidCarlisle: "You could use the raisebox variant in the box constructed with fixed height." That is exactly what I want. (I'll add an example.) – Svend Tveskæg Mar 17 '16 at 11:14
  • isn't that just using \X from one answer in an entry defined by the C column type of the other? – David Carlisle Mar 17 '16 at 11:20
  • @DavidCarlisle Hmm... I'm not sure why it doesn't work when I try to "mix" the answers. :-( Will you please create a complete answer for me? – Svend Tveskæg Mar 17 '16 at 11:43
  • your example is rather odd, the raised text trickery is for raising text within a line but you are applying it to the whole cell so it's doing nothing very useful????? – David Carlisle Mar 17 '16 at 12:36
1

The features are unconnected, you just need to use the \raisebox in the C column.

Here I used a slightly modified C column that better adds to the height while maintaining the \vcenter behaviour.

enter image description here

\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}
  • Hmmm... I forgot to mention that I would like to have the cell height equal to the heighest cell (if there is no automatic set height for all the cells). Sorry for not mentioning that from the beginning. – Svend Tveskæg Mar 17 '16 at 12:43
  • highest cell in the whole table? That's a completely different question and unrelated to the raisebox thing. – David Carlisle Mar 17 '16 at 13:01
  • Yes, the heighest cell in the table. I didn't knew that it was unrelated. Sorry for that? – Svend Tveskæg Mar 17 '16 at 13:06
  • @SvendTveskæg I can't see how they could be related (or why you are applying the raised text to a whole paragraph) – David Carlisle Mar 17 '16 at 13:08
  • You are right. I'll delete my question. – Svend Tveskæg Mar 17 '16 at 15:08
1

You can try the following code, for example:

\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

The idea is based on the two passes over data. First, we measure the maximal hight of \vbox and second pass uses it as \dimen0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.