Generaltabular/table: various questions (width, center, vspace)

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jimisola
Posts: 22
Joined: Sat Feb 02, 2008 2:54 am

tabular/table: various questions (width, center, vspace)

Post by jimisola »

Hi!

1. Is it possible to specify column width and center its context?

Code: Select all

\begin{tabular}{|p{4cm}|p{10cm}|}
        want this column do be centered & this column to be left or right adjusted\\
...
2. Is it possible to specify that a table/tabular should occupy to complete width of the page (minus margins of course)?
That is, similar to 100% if you talk XHTML/CSS.

3. I would like certain rows to have a little more vertical spacing (above and below the text in the column) as they act as headers.

4. Is it possible to add a light gray background to a row?

Regards,
Jimisola

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

tabular/table: various questions (width, center, vspace)

Post by gmedina »

The tabularx, tabulary and colortbl packages could be useful.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jimisola
Posts: 22
Joined: Sat Feb 02, 2008 2:54 am

tabular/table: various questions (width, center, vspace)

Post by jimisola »

gmedina wrote:The tabularx, tabulary and colortbl packages could be useful.
Thank you for the pointers!

I manage to use colortbl successfully and tabulary so that it matches \textwidth and with columns being aligned left, right och center.
For those that searched and ended up here:

Code: Select all

\begin{table}[h!t]
	\centering
    \begin{tabulary}{\textwidth}{|C|L|}
    ...
However, I was not able to figure out how to give row a little more spacing (question 3 in the previous post) and vertically center (i.e. not top or bottom) the text in a row as well.

Finally, I have a "\fbox{\parbox{}{..." environment where I want to limit its width to \textwidth so that it is nicely aligned with text as well tables.
How do I do this? I tried "...\parbox{\textwidth}..." without success.

Regards,
Jimisola
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

tabular/table: various questions (width, center, vspace)

Post by gmedina »

The \vphantom command (it produces a zero-width box of height and depth equal to those of its argument) can be useful. Look at the following example:

Code: Select all

\documentclass{article} 

\begin{document} 

\begin{tabular}{|c|c|c|}
  \hline
  A & B & C \\ \hline
  \vphantom{\rule{0pt}{30pt}} D & E & F \\[25pt] \hline
  G & H & I \\ \hline
\end{tabular}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jimisola
Posts: 22
Joined: Sat Feb 02, 2008 2:54 am

tabular/table: various questions (width, center, vspace)

Post by jimisola »

gmedina wrote:The \vphantom command (it produces a zero-width box of height and depth equal to those of its argument) can be useful. Look at the following example:

Code: Select all

\documentclass{article} 

\begin{document} 

\begin{tabular}{|c|c|c|}
  \hline
  A & B & C \\ \hline
  \vphantom{\rule{0pt}{30pt}} D & E & F \\[25pt] \hline
  G & H & I \\ \hline
\end{tabular}

\end{document}
Cannot get it to work with tabulary:

Code: Select all

\begin{table}[h!t]
    \centering
    \begin{tabulary}{\textwidth}{|C|L|}
        \hline
	 \rowcolor[gray]{.75}
         \vphantom{\rule{0pt}{20pt}} Col1 & Col2 \\[12pt]
        \hline 
as only Col2 is vertically centered. Only 8 google hits...

Sorry for asking all this questions, but this you have any idea on the fbox/parbox and textwidth issue?

Really appreciate your help.

Kind Regards,
Jimisola
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

tabular/table: various questions (width, center, vspace)

Post by gmedina »

Regarding the tabulary issue, you can use something like

Code: Select all

\documentclass{article} 

\usepackage{tabulary}
\usepackage{colortbl}
\usepackage{calc}
\begin{document} 

\begin{table}[!ht]
  \begin{tabulary}{\textwidth}{|C|L|}
    \hline
    Col1 & Col2 \\
    \hline
    \rowcolor[gray]{0.8}
    \vphantom{\rule{0pt}{20pt}} Col1 & \vphantom{\rule{0pt}{20pt}} Col2 \\[12pt]
  \end{tabulary}
\end{table}

\end{document}
Regarding the \fbox issue I do not understand exactly what you need. Maybe the boxedminipage package can be useful. Look at the following example (the blindtext package was loaded only to automatically generate some text):

Code: Select all

\documentclass{article}
\usepackage{boxedminipage} 
\usepackage{blindtext}

\begin{document} 

\blindtext

\noindent\begin{boxedminipage}[t]{\linewidth}
  \blindtext
\end{boxedminipage}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jimisola
Posts: 22
Joined: Sat Feb 02, 2008 2:54 am

tabular/table: various questions (width, center, vspace)

Post by jimisola »

Ok. I've attached a pdf file now with a page that illustrates my problems. The text is in Swedish hopefully that won't be an issue :)

The LaTeX is seen below.

1. I managed to get the vertical spacing in the tabulary environment. The boxing lines on top and on the left side are not visible however. Any ideas on how to resolve this?

2. The fbox issue (not having a width of text width is also illustrated) is shown in the box with the title "Definition of hot". I want it to be lined up with the tabular below otherwise it looks strange. For some reason the last item has it text stretched I'll have. I'm not sure that I like this, so if you have any idea on what it is called and how to fix it I'd appreciate it.

I really appreciate your help. It is really hard to figure some of these things out by yourself when you don't even now when to look for :)

Regards,
Jimisola

Code: Select all

\newpage
\begin{center} 
\fbox{
	\parbox{14cm}{

			\begin{center}
			\textbf{Definition av hot}
			\end{center}

			Hot är definerade som händelser eller fel som:
				\begin{itemize}
					\item sker utan påverkan från besättningen
					\item ökar den operationella komplexiteten av en flygning
					\item kräver besättningens uppmärksamhet och agerande/handhavande om säkerhetsmarginaler skall bibehållas
				\end{itemize}
	}
}
\end{center} 

\begin{table}[h!t]
	\centering
    \begin{tabulary}{\textwidth}{|C|L|}
        \hline
				\rowcolor[gray]{.75}
         \vphantom{\rule{0pt}{10pt}}Miljöhot & \vphantom{\rule{0pt}{10pt}}Exempel \\[10pt]
        \hline 
        ogynnsam (eng: adverse) väder & åskväder, turbulens, dålig sikt, vindsjuvning, risk för isbildning, icing conditions, IMC\\\hline 
        flygplats & \\\hline 
        ATC &  \\\hline 
        miljöoperativt tryck (eng: Env Op Pressure) &  \\
				\hline 
				\rowcolor[gray]{.75}				
        Flygbolagshot & Exempel \\[12pt]
        \hline
        flygplan & \\\hline 
        flygbolagoperativt tryck & \\\hline 
        kabin & \\\hline 
        dispatch/pappersarbete & \\\hline 
        ground/ramp& \\\hline 
        markunderhåll & \\\hline 
        manualer/kartor & \\\hline 
		  \end{tabulary}
	\caption{Typer av hot samt exempel}
	\label{bakgrund_tem_hot_exempel}
\end{table}
Attachments
tem-report.pdf.pdf
(16.62 KiB) Downloaded 837 times
jimisola
Posts: 22
Joined: Sat Feb 02, 2008 2:54 am

Re: tabular/table: various questions (width, center, vspace)

Post by jimisola »

The boxedminipage is exactly what I wanted. Thank you.
ubuntu_user101
Posts: 2
Joined: Tue Feb 26, 2008 2:48 am

Re: tabular/table: various questions (width, center, vspace)

Post by ubuntu_user101 »

Is it possible to set a column width in a table and set the column to be aligned to the right?
{c p{5em} l} but I still want p{5em} to be aligned to the right.
Post Reply