Newsgroups: comp.text.tex Date: Thu, 25 Mar 2004 05:00:51 GMT
Newsgroups: comp.text.tex Date: Thu, 25 Mar 2004 05:00:51 GMT
Below is a summary of width of the text in (La)Tex, and my question.
If the paper size/margins might be different, rather than specifying an explicit dimension, one can use two tex commands, \textwidth and/or \linewidth.
\textwidth is the normal width of the text on a page. It should generally be changed only in the preamble.
\linewidth is the width of lines in the current environment. Normally equal to \textwidth, it may be different within an environment such as list or quote environments.
The \linewidth can be further divided up. For example, to define a table which left column takes up 40% of the space, use
\begin{tabular}{p{0.4\linewidth}p{0.6\linewidth}} \end{tabular}
Now here is my question, if I want to put table in table, for example, still, to define a table which left column takes up 40% of the space, but this time the table is in the right column, what is the best way to do?
T
> \begin{tabular}{p{0.4\linewidth}p{0.6\linewidth}} > \end{tabular}
This will get you an overfull hbox since you don't account for the column spacing. (And of course you should have no indentation in that line.)
So either suppress column spacing (using @{}) in the relevant places in the table layout definition) or use the tabularx package.
> Now here is my question, if I want to put table in table, for > example, still, to define a table which left column takes up 40% > of the space, but this time the table is in the right column, what > is the best way to do?
Have you tried just nesting the tables? It should do what you want; if not, what's the problem? Don't forget posting a minimal example of what you did in that case.
Thomas
> I guest this is the reason why the table spread over to the next > column... Can I say something like > \begin{tabular}{p{0.4\linewidth-0.5\columnspace}p{0.6\linewidth-0.5\columnspace}}
yes, if you've loaded the calc package.
Robin
> > ... suppress column spacing (using @{}) in the relevant places in > > the table layout definition) ... > > Could you show me how to do it?
\begin{tabular}{@{}p{0.4\linewidth}@{}p{0.6\linewidth}@{}}
If you insist on vertical rules (which is a Bad Thing, for more on this read the booktabs package documentation) or need some space between the columns (which you will if they contain just text), you're better off using the tabularx package since then you don't need to know how much of \linewidth is really left for the columns:
\usepackage{tabularx} % in the preamble
\begin{tabularx}{\linewidth}{@{}>{\hsize=0.8\hsize}X>{\hsize=1.2\hsize}@{}}
Read the tabularx package documentation for more information.
Thomas
> \begin{tabular}{@{}p{0.4\linewidth}@{}p{0.6\linewidth}@{}}
one '@{}' at very first is enough: |
+
T
LaTeX normally sets the width of the tabular environment to "natural" width, i.e., determined from the contents of the columns. For narrow tables it is sometimes more pleasing to make them wider.
The 'tabular*' environments allows for setting a width; however, it is necessary to have rubber space between columns that can expand to the specified width. This can often be most easily accomplished by using an which sets the table width to 75% of the text width. This example also centers the table.
\begin{center} % put inside center environment \begin{tabular*}{0.75\textwidth}% {@{\extracolsep{\fill}}cccr} label 1 & label 2 & label 3 & label 4 \\ \hline % put a line under headers item 1 & item 2 & item 3 & item 4 \\ ... \end{tabular*} \end{center}
> And for tabulars? All my tabulars stick a bit out of my page. This > because there are long sentences in it.
Use the p column specifier instead of l:
\begin{tabular}{lp{5cm}} column one & column two \\ \end{tabular}
You can also use the `tabularx' environment (from the package with the same name) instead. It will provide an X specifier which will adjust the column width automatically.
Magnus
to make a ruber-lengthed column to stretch to the end:
\usepackage{tabularx} % in the preamble
\begin{tabularx}{\textwidth}{crllcX}
or whatever: the X column is a p-like column with implicit (i.e., stretchable) width.
Newsgroups: comp.text.tex Date: 29 Mar 2004 18:28:57 GMT
> I've got two questions on table. > > - How to make my last column of the table stretch to the end, > using the rest of the line space?
> - Does the table entry has to be on one line? > > About the 2nd question, here is my test file:
> I get the following error: > > ! LaTeX Error: Something's wrong--perhaps a missing \item. > > See the LaTeX manual or LaTeX Companion for explanation. > Type H <return> for immediate help. > ... > > l.20 ... 4 & \centering 5 & \centering 6 \\ \hline > > What's wrong?
Ulrike Fischer
> > http://www.tex.ac.uk/cgi-bin/texfaq2html?label=fixwidtab[] > >hmm, after reading it several times, I think you meant to suggest the >tabulary package: > >,----- >| The tabulary package (by the same author) provides a way of >| "balancing" the space taken by the columns of a table. The package >| defines column specifications C, L, R and J, giving, respectively, >| centred, left, right and fully-justified versions of space-sharing >| columns. The package examines how long each column would be >| "naturally" (i.e., on a piece of paper of unlimited width), and >| allocates space to each column accordingly. >`-----
actually, no. tabulary shares out the space between several variable-width columns, in an equitable way; tabularx is quicker and does an equally good job if there's only one stretchable column..
>However, I still don't know how to make a ruber-lengthed column to stretch >to the end... Could someone show me how please?
\begin{tabularx}{\textwidth}{crllcX}
or whatever: the X column is a p-like column with implicit (i.e., stretchable) width. i thought it was obvious — plainly need more examples in the faq answer (noted in list of things-to-do).
Robin
There are two basic techniques for making fixed-width tables in LaTeX: you can make the gaps between the columns stretch, or you can stretch particular cells in the table.
Basic LaTeX can make the gaps stretch: the tabular* environment takes an extra argument (before the clpr layout one) which takes a length specification: you can say things like "15cm" or "\columnwidth" here. You must also have an \extracolsep command in the clpr layout argument, inside an @ directive. So, for example, one might have
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}}lllr}
The \extracolsep applies to all inter-column gaps to its right as well; if original.
The tabularx package defines an extra clpr column specification, X; X columns behave as p columns which expand to fill the space available. If there's more than one X column in a table, the spare space is distributed between them.
The tabulary package (by the same author) provides a way of "balancing" the space taken by the columns of a table. The package defines column specifications C, L, R and J, giving, respectively, centred, left, right and fully-justified versions of space-sharing columns. The package examines how long each column would be "naturally" (i.e., on a piece of paper of unlimited width), and allocates space to each column accordingly. There are "sanity checks" so that really large entries don't cause everything else to collapse into nothingness (there's a "maximum width" that any column can exert), and so that tiny entries can't get smaller than a specified minimum. Of course, all this work means that the package has to typeset each row several times, so things that leave "side-effects" (for example, a counter used to produce a row-number somewhere) are inevitably unreliable, and should not even be tried.
The ltxtable combines the features of the longtable and tabularx packages: it's important to read the documentation, since usage is distinctly odd.
One often needs to alter the alignment of a tabular p ('paragraph') cell, but problems at the end of a table row are common. If we have a p cell that looks like
... & \centering blah ... \\
one is liable to encounter errors that complain about a "misplaced \noalign" (or the like). The problem is that the command \\ means different things in different circumstances: the tabular environment switches the meaning to a value for use in the table, and \centering, \flushright and \flushleft all change the meaning to something incompatible. Note that the problem only arises in the last cell of a row: since each cell is set into a box, its settings are lost at the & (or \\) that terminates it.
The simple (old) solution is to preserve the meaning of \\:
\def\PBS#1{\let\temp=\\% #1% \let\\=\temp }
which one uses as:
... & \PBS\centering blah ... \\
(for example).
The technique using \PBS was developed in the days of LaTeX 2.09 because the actual value of \\ that the tabular environment used was only available as an internal command. Nowadays, the value is a public command, and you can in principle use it explicitly:
... & \centering blah ... \tabularnewline
but the old trick has the advantage of extreme compactness.
The \PBS trick also serves well in array package "field format" preamble specifications:
\begin{tabular}{... >{\PBS\centering}p{50mm}} ...
Newsgroups: comp.text.tex Date: 2003-09-18 07:06:35 PST
> I'm trying to use tabularx and to align the content of the cell in the > table to the top of the cell. I'm trying: > > \begin{tabularx}[t]{\linewidth}{|p{0.2\linewidth}|X|}
The [t] goes after the {linewidth}. And it has nothing to do with the aligment of the content of the cells which is as default aligned to the top in your example. Sent a minimal document that demonstrates you problem.
Ulrike Fischer
Here is the shortest document that illustrate my question.
Thanks Shai
\documentclass{article} \usepackage{tabularx} \begin{document} \begin{tabularx}{\linewidth}[t]{|l|X|} \hline \begin{tabular}{l} Put \\ some \\ text\\ here\\ \end{tabular} & Why this is NOT in the top of the cell? \\ \hline \end{tabularx}
Just some text to separate the two tabularx environments
\begin{tabularx}{\linewidth}[t]{|l|X|} \hline \begin{tabular}[t]{l} %the only difference between the two tabularx Put \\ some \\ text\\ here\\ \end{tabular} & Why this is aligned to the top of the cell? \\ \hline \end{tabularx} \end{document}
> & Why this is NOT in the top of the cell? \\
it is. The top of the cell is the baseline of the first line. The problem only is that this first line is rather height.
Your problem has nothing to do with tabularx. You don't seem to know how the inner tabular is aligned. In the first case the middle of the tabular is used to align it with other object on the same line. In the second case the first line of the tabular is used to align it with other objects.
Look at the folowing example:
\documentclass{article} \parskip5ex %to better see the par \parindent0pt \begin{document} a first line \\ some words to start a second line \begin{tabular}{l} Put \\ some \\ text\\ here\\ \end{tabular} which ends here\\ a third line \hrulefill a first line\\ some words to start a second line \begin{tabular}[t]{l} Put \\ some \\ text\\ here\\ \end{tabular} which ends here \\ a third line \end{document}
Ulrike Fischer
Newsgroups: comp.text.tex Date: Sun, 31 Jul 2005 07:53:46 +0100
> I want to align my text to the top of the picture on the left. So I use > tables. > > But I just can't align them. Here is the test example: > > \begin{tabular}[t]{c|l} > > \begin{tabular}[t]{l} > \includegraphics[width=1.2cm,angle=90]{any-pic.eps} > \end{tabular} > & > \begin{tabular}[t]{l} > top of the line > \end{tabular} > > \end{tabular}
Read the FAQ:
Best regards,
Jose Carlos Santos
Newsgroups: comp.text.tex From: m...@mimosa.csv.warwick.ac.uk (James Kilfiger) Date: 2000/02/12
>I would like to generate a table (tabular) where each row has the same >height, either the height of the largest entry or some predetermined >value.
of each row. The rule will take up no space, but will make all the rows at least 3cm high. You could automate this with the array package, using >. To get the height of the the largest entry would require hacking internals, and probably use of the aux file
James Kilfiger
> 2. How to make a cell have a fixed minimumheight. This may be a minimum > height (there is a problem anyway if the text is too long). Because > these cells are intended for longer text entries, I make them as > minipages right now. This would be very good in order to have possible > footnotes in the right place
Use a \strut or a \rule with width 0 and the height you need.
Ulrike Fischer
> 2. How to make a cell have a fixed minimumheight.
Francois Patte
> 2. How to make a cell have a fixed minimumheight.
(or use \rule)
Donald Arseneau
Newsgroups: comp.text.tex From: Thomas Lotze <T.Lo...@tpi.uni-jena.de> Date: 2000/05/31
> This does not look good. The H's touch the upper \hline. I would have > expected LaTeX to make a better job of this, but now I need to know how > to change the height between the \hlines or to do somethin else that > solves the problem. I have a quite a few tables like this so.....
Use the booktabs package. It does a better job with tables, and if you need to insert extra space, it provides the command \addlinespace.
Thomas Lotze
Newsgroups: comp.text.tex From: Jean-Come Charpentier <Jean-Come.Charpent...@wanadoo.fr> Date: Mon, 23 Jan 2006
> does anyone know how to set the height of rows in table? > I want to make every row to have the same height, and vertical > alignment be middle of the cell.
I think that the simplest is to use strut. Vertical alignment in the middle of the cell is not very clear. If you align the baseline with the middle of the cell, I'm not sure it looks centered. It's why the \Strut macro has an optional argument.
\documentclass{article} \usepackage{array} \newlength{\struthd} \newcommand*\Strut[2][-0.3]{% \setlength{\struthd}{#2}% \rule[#1\struthd]{0pt}{\struthd}% } \begin{document} $\displaystyle\frac{1}{2}$\Strut{2\baselineskip}\vrule \vspace{5mm} $\displaystyle\frac{1}{2}$\Strut[-0.375]{2\baselineskip}\vrule \vspace{5mm} $\displaystyle\frac{1}{2}$\Strut[-0.5]{2\baselineskip}\vrule \vspace{5mm} \begin{tabular}{|>{\Strut[-0.5]{60pt}}r|c|l|} \hline text & with & a strut \\\hline column one & column two & column three \\\hline \end{tabular} \end{document}
Jean-Come Charpentier
If you already know the height of your cells, then you could use an empty parbox to set the height of a row in every first column:
\newlength{\myheight} \setlength{\myheight}{3cm} \begin{tabular}{|l|l|l|}\hline \parbox[c][\myheight][c]{0cm}{} row 1 & row 2 & row 3\\\hline \parbox[c][\myheight][c]{0cm}{} row 1 & row 2 & row 3 \\\hline \end{tabular}
To determine \myheight, maybe the command \settoheight might be useful.
Regards, Catilina
Newsgroups: comp.text.tex Date: Thu, 20 Oct 2005
I like to construct a table with different heights of rows. For example, the first row (colored) has an one line text with footnote size characters (with some identifying items for the next row), the second row also has an one line text, but with normal size of characters. I like that high of rows will be adjusted to height of characters. Is thehe any possibility to acieve this?
I look in FAQ and found the solution, how ones can change the whole row in table (using array package), but unfortunately, this work only for change the size (or style) of characters but the height of row remain the same as the other rows with normal size characters.
Look around by Google gives modest results, from that this is not wise to do to that this is almost impossible in LaTeX.
Regards, Zarko
tabular use for the rows the height of the strutbox of the fontsize that is active at the start of the tabular.
So you could try the following: set a small fontsize e.g. \tiny before the tabular. And in the cells use e.g. \small\strut …. or \normalsize\strut. (You need the \strut only in one cell in a row and it can come at the end). If you use a p-column you should put a \strut at the start and at the end of the text.
Ulrike Fischer
> So you could try the following: set a small fontsize e.g. \tiny before > the tabular.
And the strut is scaled by \arraystretch. Probably the following redefinition already helps:
\renewcommand{\arraystretch}{0}
Heiko <oberd…@uni-freiburg.de>
After some experiments i found a solution which gives me desired behavior. In preamble I put macro from FAQ UK, omit the suggested start size \tiny.
Not just minimal example (but it show all desired look-out) what I did:
\usepackage{array,tabularx,colortbl}
% for fixed size of cells in tabularx % for colored cells
% from FAQ UK \newcolumntype{$}{>{global\let\currentrowstyle\relax}} \newcolumntype{^}{>{currentrowstyle}} \newcommand\rowstyle[1]{gdef\currentrowstyle{#1}% #1\ignorespaces}
\caption{ISO 646 - ISO 7 bitni kod, osnovni.} \hline \rowstyle{scriptsize\strut}% this adjust the rowh height and % character size \rowstyle{normalsize\strut}% this adjust the rowh height and % character size & DLE
well, a some problems still remain. the first one (quite disturbing) is that the space above text in rows is not the same as bellow, that second one is that the width of cells and the right side of rows don't align anymore.
regards, Zarko
You need to put the size commands in every cell. It's only the strut that is needed only once per row.
> After some experiments i found a solution which gives me desired > behavior. .. some problems still remain. the first one (quite disturbing) > is that the space above text in rows is not the same as bellow,
That is the normal behaviour of the strut/tabular. If you want more space you will have to use another invisible rule with more height (or less depth).
> that > second one is that the width of cells and the right side of rows don't > align anymore. Do you or anybody how some idea how to copy with this?
With array it matters if you put in \multicolumn the rule before or after the cell.
\parskip1cm
\fbox{strut N}
\hline N \\\hline
Ulrike Fischer
> \documentclass[a4paper,12pt]{book} > ... > \end{document}
following your example I rearrange the positions of | in my tables and now the all cells align as it is expected!
thank you very much for your valuable help!
regards, Zarko
Newsgroups: comp.text.tex From: Donald Arseneau <a...@triumf.ca> Date: 20 Apr 2001
> I would like to have all cells of the same height in a table. Is there a way > or a package that does it? Thanks for your help.
That is the default, as long as everything fits, right?
Put \renewcommand{arraystretch}{1.5} before the tabular. Choose the number so the biggest cells fit.
Donald Arseneau
I assume you have different (or sometimes even no) material in cells, or even whole rows? If this is the case then there are two simple ways to make sure your desired height is guaranteed everywhere.
Approach. Take your highest symbol or text token (e.g. here the letter A)
Define a strut, or box, of zero width and defined height, which you place into every first cell of an empty row.
Primitive, but useful.
Dr. Oliver Corff
> >> and say \phantom{A} in the first cell of each empty row. > > You misspelled \vphantom, didn't you?. > > Not exactly. There are \phantom, \hphantom and \vphantom. I just thought > \phantom does it here.
I would say you need a \vphantom here. IIRC \phantom inserts an empty box with width, height and depth of its argument, \hphantom inserts a box with zero height and zero depth and \vphantom inserts a box with zero width. So first column of every row. Since what is important here is the height of the symbol, I would use \vphantom
Sven Bovin <m…@student.kuleuven.ac.be>
Newsgroups: comp.text.tex From: Peter Flynn <p...@silmaril.ie> Date: Tue, 08 Jan 2002
> LTXtable, longtable, tabularx and LaTable are all working very well > for me. However, I am still looking for an efficient way to center > text vertically in a cell. For example, a long passage of text in a > certain cell causes the entire row to be four lines in height. The > cell to the right (same row) has only one word. It appears at the > very top of its cell with three lines of white space below it. How do > I center the one word "top-to-bottom" in its cell?
&\vbox to2cm{hsize=3cm\null\vfill stuff\vfill}&
Peter Flynn
read the documentation of the array package if you want to do more than trivial table typesetting. Something like m columns, page 2 or so.
David Kastrup
> LTXtable, longtable, tabularx and LaTable are all working very well > for me.
With those packages you have the m (or M?) column type. Use it for the 4-line p cplumn. (Yes, you need to vertically center the 4-line column, not the 1-line. That is a source of confusion.)
Donald Arseneau
> I read booktabs.dvi but I didn't read anything that prohibits me from > centering text vertically in a cell. The author of booktabs.dvi says > never use vertical rules, where a rule is a line.
While not prohibited explicitly, vertical centering may make a (formal) table harder to read, because horizontal rules are intended to be used sparingly. It's less obvious where the cell boundaries are — and therefore, what the text is vertically centered relative to — than in a gridlined tableau.
> Anyway, m-column apears to be working. Unfortunately, the formatting > also applies to the cell in the head which has only 1 line of text, > not 4.
You can use \multicolumn to override column formatting for an individual cell. See a LaTeX manual for usage information.
Scott Pakin <p…@uiuc.edu>