Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: vertical and horizontal align cell in a longtable

1,101 views
Skip to first unread message
Message has been deleted

Igor Pechtchanski

unread,
Mar 7, 2005, 6:43:47 PM3/7/05
to
On Mon, 7 Mar 2005, Daniel Farfán Muńoz wrote:

> Hi everyone,
>
> I have the following table:
>
> \begin{longtable}{|l|c|c|c|c|c|c|c|c|}
> \hline
> Paleoflora&\rotatebox{90}{Steinmann (1922)}&\rotatebox{90}{Jaworski
> (1923)}&\rotatebox{90}{Tavera (1960)}&\rotatebox{90}{Campo II
> 2003}&\rotatebox{90}{Moisan (2004)}&\rotatebox{90}{Campo II
> 2004}&\rotatebox{90}{\centering Pérez (2005)}&\rotatebox{90}{Leppe
> (2005)}\\
> \hline \endhead
> \hline \endfoot
> \emph{Antevsia} sp.&&&&&&&&X\\
> \emph{Asterotheca fuchsi}&&&X&&X&X&&X\\
> \emph{Asterotheca rigbyana}&&&&X&X&X&&X\\
> \emph{Asterotheca} sp.&&&&&&X&&\\
> \emph{Baiera} sp.&&&X&&&&&\\
> \emph{Baiera africana}&&&&&&&&X\\
> .
> .
> .
> \end{longtable}
>
> And two questions:
> 1. How i can center vertically and horizontally the first cell of the
> table (Paleoflora)?

The horizontal bit is easy: use \multicolumn{1}{|c|}. The vertical is
much harder -- I'm not even sure it's possible to do in general (I'd love
to be proven wrong). It *is* possible to do this for one row, using a
dirty hack below.

> 2. How i can break the authors (Steinmann (1922)), so it looks like
> Steinman
> (1922)
> ?

This one is also easy: use \shortstack[c]{Steinmann\\(1922)}.

So, here's the promised dirty hack (actually, not too dirty, but will only
work for one row):

% In preamble
\makeatletter
\newlength{\HeaderHeight}\setlength\HeaderHeight{0pt}
\newlength{\HeaderHeightSave}
\newlength{\HeaderHeightTmp}
\AtBeginDocument{\global\setlength\HeaderHeightSave{\the\HeaderHeight}}
\def\AddToHeader#1{\settoheight{\HeaderHeightTmp}{#1}\ifdim\HeaderHeightTmp>\HeaderHeight\global\setlength\HeaderHeight\HeaderHeightTmp\typeout{Increased \string\HeaderHeight\ to \the\HeaderHeight}\fi\rotatebox{90}{\makebox[\HeaderHeight][c]{\rotatebox{-90}{#1}}}}
\AtEndDocument{\protected@write\@auxout{}{\string\global\string\setlength\string\HeaderHeight{\the\HeaderHeight}}\ifdim\HeaderHeight=\HeaderHeightSave\else\typeout{Row height has changed. Rerun LaTeX.}\fi}
\makeatother

% In document
\begin{longtable}{|l|c|c|c|c|c|c|c|c|}
\hline
\multicolumn{1}{|c|}{\AddToHeader{Paleoflora}}%
&\AddToHeader{\rotatebox{90}{\shortstack[c]{Steinmann\\(1922)}}}%
&\AddToHeader{\rotatebox{90}{\shortstack[c]{Jaworski\\(1923)}}}%
&\AddToHeader{\rotatebox{90}{\shortstack[c]{Tavera\\(1960)}}}%
&\AddToHeader{\rotatebox{90}{\shortstack[c]{Campo II\\2003}}}%
&\AddToHeader{\rotatebox{90}{\shortstack[c]{Moisan\\(2004)}}}%
&\AddToHeader{\rotatebox{90}{\shortstack[c]{Campo II\\2004}}}%
&\AddToHeader{\rotatebox{90}{\shortstack[c]{Prez\\(2005)}}}%
&\AddToHeader{\rotatebox{90}{\shortstack[c]{Leppe\\(2005)}}}\EndHeader\\
\hline \endhead
\hline \endfoot
\emph{Antevsia} sp.&&&&&&&&X\\
\emph{Asterotheca fuchsi}&&&X&&X&X&&X\\
\emph{Asterotheca rigbyana}&&&&X&X&X&&X\\
\emph{Asterotheca} sp.&&&&&&X&&\\
\emph{Baiera} sp.&&&X&&&&&\\
\emph{Baiera africana}&&&&&&&&X\\
\end{longtable}

HTH,
Igor
P.S. LaTeX gurus: comments on the above code are welcome.
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pech...@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ ig...@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D.
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT

Igor Pechtchanski

unread,
Mar 7, 2005, 7:14:41 PM3/7/05
to
On Mon, 7 Mar 2005, Igor Pechtchanski wrote:

> % In document
> [snip]


> &\AddToHeader{\rotatebox{90}{\shortstack[c]{Leppe\\(2005)}}}\EndHeader\\

^^^^^^^^^^
Ugh, this one slipped through. \EndHeader is an artifact of an earlier
attempt, and needs to be removed. Sorry.
Igor

Daniel Farfán Muñoz

unread,
Mar 9, 2005, 6:40:56 AM3/9/05
to
Thanks, Igor

I have found a different way to solve the problem (based on yours and a
hint found in LaTeX Tutorials, Indian TEX Users Group ):

% In preamble
\newcommand{\vertext}[1]{\multicolumn{1}{m{.8cm}|}{\centering\rotatebox{90}{\shortstack{#1}}}}

% In document
\begin{longtable}{|l|c|c|c|c|c|c|c|c|}
\hline

\multicolumn{1}{|c|}{Paleoflora}&\vertext{Steinmann\\(1922)}&\vertext{Jaworski\\(1923)}&\vertext{Tavera\\(1960)}&\vertext{Campo
II\\2003}&\vertext{Moisan\\(2004)}&\vertext{Campo
II\\2004}&\vertext{Pérez\\(2005)}&\vertext{Leppe\\(2005)}\\


\hline \endhead
\hline \endfoot
\emph{Antevsia }sp.&&&&&&&&X\\
\emph{Asterotheca fuchsi}&&&X&&X&X&&X\\
\emph{Asterotheca rigbyana}&&&&X&X&X&&X\\
\emph{Asterotheca }sp.&&&&&&X&&\\
\emph{Baiera }sp.&&&X&&&&&\\
\emph{Baiera africana}&&&&&&&&X\\
.
.
.
\end{longtable}

But this way doesn't auto adjust the columns widths as your solution.
In both solutions, the longest author name (Steinmann) touches the top
of the table. How to increase the distance from the name to the top of
the table?

Thanks very much,
Daniel Farfán Muñoz

David Carlisle

unread,
Mar 9, 2005, 7:24:33 AM3/9/05
to

> How to increase the distance from the name to the top of
> the table?

easiest would be to make sure that the box that you rotate is bigger
than the word, eg

\newcommand{\vertext}[1]{\multicolumn{1}{m{.8cm}|}{\centering\rotatebox{90}=
{\shortstack{\mbox{ }#1\mbox{ }}}}}

0 new messages