Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Scenario

Plese see the screenshot below. The top table is produced using minipage-typed column and the bottom table is produced using m{}.

WITHOUT using \fboxsep approach (that was already answered here), how to modify the bottom table such that it looks like the top table?


Screenshot

alt text


Minimal Code

\documentclass{article}
\usepackage{array,calc,longtable}

\tabcolsep=5mm
\arrayrulewidth=2pt

\newcolumntype{A}
{
     >{\begin{minipage}{0.3\linewidth-2\tabcolsep-1.5\arrayrulewidth}%
     \vspace{\tabcolsep}\centering}%
    c%
    <{\vspace{\tabcolsep}\end{minipage}}%   
}

\newcolumntype{B}
{
     @{}>{\centering}%
    m{0.3\linewidth-0\tabcolsep-1.5\arrayrulewidth}%
    <{}@{}%
}

\def\pic{\rule{2.5cm}{1cm}}
\begin{document}

\begin{longtable}{|*2{A|}}\hline
\pic & \pic \tabularnewline\hline
\end{longtable}

\begin{longtable}{|*2{B|}}\hline
\pic & \pic \tabularnewline\hline
\end{longtable}

\end{document}
share|improve this question
1  
Why do you need only one column type for all your examples? Where is the problem to use A für something and type B for math, type C for math with align, and type D for ...?? –  Herbert Jan 8 '11 at 18:47
    
@Herbert: This question is related to your and @Leo's comment in another question (tex.stackexchange.com/questions/8437/…). Shortly speaking, I want to remove minipage-typed column if m{} can produce the same output. Creating distinct column type for each column (as you said above) has already been considered recently. :-) –  xport Jan 8 '11 at 18:56
2  
And why, exactly, did this beg another question? It is redundant. Excess. –  morbusg Jan 8 '11 at 19:24
    
@morbusg, I want to remove minipage and change it to m{}. –  xport Jan 8 '11 at 19:28
add comment

1 Answer 1

up vote 1 down vote accepted
\documentclass{article}
\usepackage{array,calc,longtable,varwidth}

\tabcolsep=5mm
\arrayrulewidth=2pt

\newcolumntype{A}
{
     >{\begin{minipage}{0.3\linewidth-2\tabcolsep-1.5\arrayrulewidth}%
     \vspace{\tabcolsep}\centering}%
    c%
    <{\vspace{\tabcolsep}\end{minipage}}%   
}

\newsavebox\TBox
\newlength\THeight
\newlength\TWidth

\newenvironment{saveTBox}[1][0.5\linewidth]
  {\begin{lrbox}{\TBox}\varwidth{#1}}
  {\endvarwidth\end{lrbox}%
   \THeight=\ht\TBox \advance\THeight by \dp\TBox \advance\THeight by 30pt
   \TWidth=\wd\TBox\advance\TWidth by 30pt
   \minipage[c][\THeight][c]{\TWidth}\centerline{\usebox\TBox}\endminipage}

\newcolumntype{B}{@{}>{\saveTBox}c<{\endsaveTBox}@{}}


\def\pic{\rule{2.5cm}{1cm}}
\begin{document}

\begin{longtable}{|*2{A|}}\hline
\pic & \pic \tabularnewline\hline
\end{longtable}

\begin{longtable}{|*2{B|}}\hline
\pic & \pic \tabularnewline\hline
\end{longtable}

\end{document}

alt text

share|improve this answer
    
@Herbert, why does it become more complicated? Actually I am interested in changing minipage-typed to m{}. :-) –  xport Jan 8 '11 at 19:23
    
@xport: it depends to the contents. If the contents has is no displayed or has no linebreaks it can be done easier as already posted multiple times. –  Herbert Jan 8 '11 at 19:43
    
@Herbert, thanks for this solution. Tomorrow I will revisit this again. I noticed the column width expands automatically that might break my real scenario. –  xport Jan 8 '11 at 20:23
    
@Herbert: There is one thing that looks "strange", i.e., the equation number gets displaced to the left from the original position. Is there a trick to make the equation number still in the correct position? –  xport Jan 10 '11 at 14:31
    
@xport: columntype A or B? The align environment works only for cilumntype A –  Herbert Jan 10 '11 at 15:27
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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