Difference between revisions of "Vertically Centered Boxes"

From Wiki
Jump to navigation Jump to search
(simplify the macros)
Line 9: Line 9:
 
</texcode>
 
</texcode>
  
===In ConTeXt: ???===
+
===In ConTeXt:===
 
 
Please note that this is only my suggestion. I believe there must be an easier way too!
 
 
 
For the first box:
 
  
 
<texcode>
 
<texcode>
\setupTABLE[frame=off]
+
a box with a table:
\setupTABLE[c][1,2][align=lohi]
+
\framed
\bTABLE
+
  [location=middle, % vertically centered
\bTR\bTD
+
    align=flushleft, % align=no (default) is a normal hbox
a box with a table:
+
                    % align=flushleft/middle/flushright/normal is used for multiple lines
\eTD\bTD[frame=on]
+
    offset=5pt]     % to make the frame wider (as in LaTeX)
{\bTABLE[frame=off]
+
  {1\\2\\3}
\bTR\bTD 1 \eTD\eTR
 
\bTR\bTD 2 \eTD\eTR
 
\bTR\bTD 3 \eTD\eTR
 
\eTABLE}
 
\eTD\eTR
 
\eTABLE
 
</texcode>
 
 
 
or
 
  
<texcode>
+
a midaligned parbox:
a box with a table: \vcenter{\framed{
+
\framed
\bTABLE[frame=off]
+
  [location=middle, % vertically centered
\bTR\bTD 1 \eTD\eTR
+
    align=normal,    % justified alignment
\bTR\bTD 2 \eTD\eTR
+
    frame=off,      % no frame
\bTR\bTD 3 \eTD\eTR
+
    width=1em]       % make box 1em wide; note that line breaking is not the same as in LaTeX (?)
\eTABLE}}
+
  {1 2 3}
 
</texcode>
 
</texcode>
  
It works on older ConTeXt distributions, here it seems to be broken:
+
<context>
 +
a box with a table:
 +
\framed
 +
  [location=middle, % vertically centered
 +
    align=flushleft, % align=no (default) is a normal hbox
 +
                    % align=flushleft/middle/flushright/normal is used for multiple lines
 +
    offset=5pt]      % to make the frame wider (as in LaTeX)
 +
  {1\\2\\3}
  
<context>
+
a midaligned parbox:
a box with a table: \vcenter{\framed{
+
\framed
\bTABLE[frame=off]
+
  [location=middle, % vertically centered
\bTR\bTD 1 \eTD\eTR
+
    align=normal,    % justified alignment
\bTR\bTD 2 \eTD\eTR
+
    frame=off,      % no frame
\bTR\bTD 3 \eTD\eTR
+
    width=1em]       % make box 1em wide; note that line breaking is not the same as in LaTeX (?)
\eTABLE}}
+
  {1 2 3}
 
</context>
 
</context>
  
The second box <b>should</b> be possible to typeset as
+
If you need a proper table (the one above only had one column), use <code>\bTABLE ... \eTABLE</code> or similar instead of <code>1\\2\\3</code>. See [[Tables Overview]] for more possibilities.
<texcode>
+
 
\setupTABLE[frame=on]
 
\setupTABLE[c][1,2][align=lohi]
 
\bTABLE
 
\bTR\bTD
 
    a midaligned parbox:
 
\eTD\bTD[offset=0pt,width=1em]
 
    1 2 3
 
\eTD\eTR
 
\eTABLE
 
</texcode>
 
  
but it doesn't work:
+
A broken example (for the second box):
  
 
<context>
 
<context>
Line 73: Line 57:
 
\bTABLE
 
\bTABLE
 
\bTR\bTD
 
\bTR\bTD
    a midaligned parbox:
+
  a midaligned parbox:
 
\eTD\bTD[offset=0pt,width=1em]
 
\eTD\bTD[offset=0pt,width=1em]
    1 2 3
+
  1 2 3
 
\eTD\eTR
 
\eTD\eTR
 
\eTABLE
 
\eTABLE
 
</context>
 
</context>

Revision as of 10:49, 29 July 2005

In LaTeX

\documentclass{article}
\begin{document}
a box with a table:
\fbox{\begin{tabular}[c]{l}1\\2\\3\end{tabular}}\par
a midaligned parbox: \parbox[c]{1em}{1 2 3}
\end{document}

In ConTeXt:

a box with a table:
\framed
   [location=middle, % vertically centered
    align=flushleft, % align=no (default) is a normal hbox
                     % align=flushleft/middle/flushright/normal is used for multiple lines
    offset=5pt]      % to make the frame wider (as in LaTeX)
   {1\\2\\3}

a midaligned parbox:
\framed
   [location=middle, % vertically centered
    align=normal,    % justified alignment
    frame=off,       % no frame
    width=1em]       % make box 1em wide; note that line breaking is not the same as in LaTeX (?)
   {1 2 3}

If you need a proper table (the one above only had one column), use \bTABLE ... \eTABLE or similar instead of 1\\2\\3. See Tables Overview for more possibilities.


A broken example (for the second box):