10

I have now been working on fixing this problem for some time and I have read through some forums on the Internet and tried different things, but I can't solve this problem.

I am looking to have some text vertically aligned at the bottom inside a long table, preferable with a line about the text for a signature. Furthermore I would like to have control over the minimum height of the rows.

I've seen that I can align text vertically with the array package and from Vertical aligning in longtable environment it also seems to be possible inside a long table.

I should probably also say that I am generating my tables with R's knitr package and xtable's print.xtable().

I have some working code here (and also a screenshot of what I currently have below the code).

\documentclass[12pt]{article}
\usepackage{longtable}
\usepackage[landscape]{geometry}
\usepackage{colortbl} % 
\begin{document}

\begin{longtable}{cccp{6.6cm}p{3.6cm}p{3.6cm}}
  \hline
Date & Event & Type & Note & Bank & Banrak Obama \\ 
  \hline \endhead \rowcolor[gray]{.95}Sep 02 2012 & 005 & CPP & ww &John Doe, \#, '\# & Some Name \\ 
  Sep 10 2012 & 006 & IND & Quisque luctus purus non arcu feugiat pharetra. In hac habitasse platea dictumst. &John Doe, \#, '\# & Some Name \\ 
   \rowcolor[gray]{.95} Sep 22 2012 & 002 & CON & I sat around thinking about my life. & John Doe, \#,  ID'\# & Some Name \\ 
  Sep 23 2012 & 003 & OUT & Quisque luctus purus non arcu feugiat pharetra. In hac habitasse platea dictumst. Donec non sapien tellus, et condimentum lectus. Aenean eu mollis velit. Morbi dignissim commodo sapien, bibendum consectetur libero mattis eu. Aliquam tristique pharetra elit et posuere. Nullam adipiscing, purus at volutpat consequat. &John Doe, \# ID'\# & Some Name \\ 
   \rowcolor[gray]{.95} Sep 23 2012 & 004 & OUT & Outreach, Fish. \& $\backslash$ \# Quisque luctus purus non arcu feugiat pharetra. In hac habitasse platea dictumst. Donec non sapien tellus, et condimentum lectus. Aenean eu mollis velit. Morbi dignissim commodo sapien, bibendum consectetur libero mattis eu. Aliquam tristique pharetra elit et posuere. Nullam adipiscing, purus at volutpat consequat. &John Doe, \# ID'\# & Some Name \\ 
  Sep 23 2012 & 003 & OUT & Quisque luctus purus non arcu feugiat pharetra. In hac habitasse platea dictumst. Donec non sapien tellus, et condimentum lectus. Aenean eu mollis velit. Morbi dignissim commodo sapien, bibendum consectetur libero mattis eu. Aliquam tristique pharetra elit et posuere. Nullam adipiscing, purus at volutpat consequat. &John Doe, \# ID'\# & Some Name \\ 
   \rowcolor[gray]{.95} Sep 23 2012 & 004 & OUT & Outreach, Fish. \& $\backslash$ \# Quisque luctus purus non arcu feugiat pharetra. In hac habitasse platea dictumst. Donec non sapien tellus, et condimentum lectus. Aenean eu mollis velit. Morbi dignissim commodo sapien, bibendum consectetur libero mattis eu. Aliquam tristique pharetra elit et posuere. Nullam adipiscing, purus at volutpat consequat. &John Doe, \# ID'\# & Some Name \\ 
   \hline
\hline
\label{PN.df}
\end{longtable}

\end{document}

enter image description here

Eric Fail
  • 1,077
  • 1
    The columntype b{<width>} vertically aligns at the bottom (p aligns at the top, m at the middle). You may further define minimum row (where in that vertical space should be the text’s baseline?). For a tabular-globe use you can redefine \arraystretch, e.g. \renewcommand{\arraystretch}{1.5}. – Qrrbrbirlbel Dec 05 '12 at 05:54
  • @Qrrbrbirlbel, thank you for commenting on my question. I am a bit in over my head here, but what is tabular-globe? Could you refer me to a source or maybe share an working example with me? Also, it is my understanding that longtbale' overwrites anyb{}'s orm{}`'s, but maybe that is what you are circumventing by your suggestion? Thanks, Eric. – Eric Fail Dec 05 '12 at 06:39
  • @EricFail no longtable doesn't do anything with the column specifiers other than pass them to the underlying tabular implementation. b{..} means the same in longtable as it does in tabular. – David Carlisle Dec 05 '12 at 14:47
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – samcarter_is_at_topanswers.xyz Apr 04 '18 at 11:50

2 Answers2

9

I would define a new column as in the following example. The newcolumntype command can be very useful for achieving the sorts of affects you're looking for.

\newcolumntype{B}{>{\begin{minipage}[b]{6.6cm}\raggedright{}}c<{\end{minipage}}}

It's not essential to use \raggedright, but I think fully justified text in rather narrow columns looks unappealing and is more difficult to read. Anyhow, if you don't like the \raggedright remove it from my code. (It would be interesting to see what others have to say on this point.)

If you want something that behaves a bit more like p{...}, you can also define a new column type that takes an argument:

\newcolumntype{B}[1]{>{\begin{minipage}[b]{#1}\raggedright{}}c<{\end{minipage}}}

You can set a minimum row height by inserting an 0pt width strut at the beginning of each line of your table. You could define it as

 \newcommand{\minrowheight}{\rule{0pt}{4ex}\relax}

If you don't want to enter this manually into each row (that would be a pain) you can do it when you declare the columns:

\begin{longtable}{>{\minrowheight}cccB{6.6cm}p{3.6cm}p{3.6cm}}

You meniton some conflicts with other packages caused by the > to the first comlumn while there doesn't seem to be a problem with the new column type B. If that's the case, then you can place the code for the minimum row height at the very end of the definition for newcolumntype B.

\newcolumntype{B}[1]{>{\begin{minipage}[b]{#1}\raggedright{}}c<{\end{minipage}\minrowheight}}

You don't want to put it in the minipage environment. That will not create the visual effect you want at all. (Try to see what happens.) It should either be placed before or after the minipage. Hopefully this will be a fix for how your row coloring works.

Here's MWE that includes these suggestions and includes a signature line.

\documentclass[12pt]{article}
\usepackage{longtable}
\usepackage[landscape]{geometry}
\usepackage{colortbl} % 
\newcolumntype{B}[1]{>{\begin{minipage}[b]{#1}\raggedright{}}c<{\end{minipage}\minrowheight}}
\newcommand{\minrowheight}{\rule{0pt}{8ex}\relax}
\newcommand{\signatureLine}[1]{\begin{minipage}{3.6cm}\rule{3.6cm}{0.4pt}\newline#1\end{minipage}}
\pagestyle{empty}
\begin{document}
\begin{longtable}{cccB{6.6cm}p{3.6cm}p{3.6cm}}
  \hline
 Date & Event & Type & Note & Bank & Banrak Obama \\ 
  \hline \endhead \rowcolor[gray]{.95}Sep 02 2012 & 005 & CPP & ww &\signatureLine{John Doe, \#, '\#} & \signatureLine{Some Name} \\ 
  Sep 10 2012 & 006 & IND & Quisque luctus purus non arcu feugiat pharetra. In hac habitasse platea dictumst. &\signatureLine{John Doe, \#, '\#} & \signatureLine{Some Name} \\ 
   \rowcolor[gray]{.95} Sep 22 2012 & 002 & CON & I sat around thinking about my life. & \signatureLine{John Doe, \#,  ID'\#} & \signatureLine{Some Name} \\ 
  Sep 23 2012 & 003 & OUT & Quisque luctus purus non arcu feugiat pharetra. In hac habitasse platea dictumst. Donec non sapien tellus, et condimentum lectus. Aenean eu mollis velit. Morbi dignissim commodo sapien, bibendum consectetur libero mattis eu. Aliquam tristique pharetra elit et posuere. Nullam adipiscing, purus at volutpat consequat. &\signatureLine{John Doe, \# ID'\#} & \signatureLine{Some Name} \\ 
   \rowcolor[gray]{.95} Sep 23 2012 & 004 & OUT & Outreach, Fish. \& $\backslash$ \# Quisque luctus purus non arcu feugiat pharetra. In hac habitasse platea dictumst. Donec non sapien tellus, et condimentum lectus. Aenean eu mollis velit. Morbi dignissim commodo sapien, bibendum consectetur libero mattis eu. Aliquam tristique pharetra elit et posuere. Nullam adipiscing, purus at volutpat consequat. &\signatureLine{John Doe, \# ID'\#} & \signatureLine{Some Name} \\ 
\hline
\label{PN.df}
\end{longtable}
\end{document}

which gives an appearance like:

enter image description here

My choice of minimum row height was completely arbitrary. But working in units of ex is standard for vertical heights (it's essentially the height of the letter x.

Now what would be nice is to be able to disable the minimum row height for the column headers. This can be done, by setting some flags. That can get a bit tricky and technical. But then this is also going beyond what you were looking for.

You mention something about a line about the text for a signature. I'm not really clear on what you're looking for on that point.

A.Ellett
  • 50,533
  • Dear A.Ellett, this is crazy impressive. I've been at it for more then 12 hours now, and I have a really hard time grasping how to implement this in my world, but I really appreciate your answer and I will spend some more time looking at it in the morning! Thanks! – Eric Fail Dec 05 '12 at 05:47
  • 1
    @Eric Fail: And on that note, welcome to TeX.SE. – Peter Grill Dec 05 '12 at 06:09
  • Dear A.Ellett, the line about the text for a signature part is me looking to create a small line above the name, like in this and this TeX.SE example, for John Doe and some Name to sign on. Right now I'm fighting to get R's knitr package to pass the > in the {\minrowheight}cccB{6.6cm}p{3.6cm}p{3.6cm}} into my .tex file from my .Rnw file. – Eric Fail Dec 05 '12 at 06:28
  • 1
    Does knitr accept the > in your preamble when defining the new column type B? If yes, then you can define a new column type for the first column to get around this. \newcolumntype{C}{>{\minrowheight}c}. – A.Ellett Dec 05 '12 at 14:17
  • Are the entries in the last column always the same? This is a question regarding your signature line. – A.Ellett Dec 05 '12 at 14:18
  • @A.Ellett, I really appreciate the time you put into helping me. I am learning a lot about \LaTeX through your answers and questions. Thanks a lot! Your workaround worked, but it also conflicts with my \rowcolor that I am passing into the table via an add.to.row command in the print.xtable from the xtable package. I could live without the \rowcolor if I managed to produce some kind of horizontal lines. I'll keep working on it and keep posting in this tread if I find a solution. Thanks! – Eric Fail Dec 05 '12 at 17:04
  • @A.Ellett, the entries in the last column is not always the same, the entries in the second to last column, the one that says John Doe is always the same, both are cells where I am looking to produce the signature line. – Eric Fail Dec 05 '12 at 17:08
  • 1
    @EricFail, I've slightly modified my solution to address a different approach to getting the minrowheight to take effect. I've put the modification toward the end of my answer. – A.Ellett Dec 05 '12 at 17:42
  • @A.Ellett, thank again! Works like a charm! Now I only need to retain control of the header. Here is a real life illustration of what I mean by a line about the text for a signature. The black line in the last tow columns, does this explain it? – Eric Fail Dec 05 '12 at 19:33
  • @A.Ellett, I figured out a solution with the signature-line (simply -----), but I am still interested to retain control of the table headings, so that they do not follow the rule for the rest of the table. You mentioned something with a hook at some point, could yo point me to a source where I can read more about this? Thanks. – Eric Fail Dec 07 '12 at 19:48
6

Explanation to my comment:

The columntype b{<width>} vertically aligns at the bottom (p aligns at the top, m at the middle). You may further define minimum row (where in that vertical space should be the text’s baseline?). For a tabular-globe use you can redefine \arraystretch, e.g. \renewcommand{\arraystretch}{1.5}.


The column type b{<width>} is probably what you’re looking for. It works quite like p and m, so as David Carlisle (and he ought to know it) said they are just forwarded to the underlying tabular.

The column type l, c and r contain only one line, so they are in fact the reference for the vertical alignment of p, m and b.

In your case, I would even replace the last two columns with an l column as they are always shorter then the given width, but YMMV.

So without changing the content of your table but with the column specification {cccb{6.6cm}ll} you’ll get enter image description here.

In that Lorem Ipsum example you get warnings about underfull hboxes which is no surprise as p, m and b are justified. With the array package (which is loaded by colortbl) you can automatically make the content of b ragged right {ccc>{\raggedright}b{6.6cm}ll} and you get
enter image description here

For changing row height, you may redefine the macro \arraystretch, its default is 1.0. With for example \renewcommand*{\arraystretch}{1.5} you get:
enter image description here

If you need more control over the individual height of rows you may use struts as A.Ellett did in his answer.

Qrrbrbirlbel
  • 119,821