Graphics, Figures & TablesTable in table causes bad alignment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
zer0nimo
Posts: 12
Joined: Wed Jul 29, 2009 3:20 am

Table in table causes bad alignment

Post by zer0nimo »

Hi!

I'm trying to make some nested tabulars but by doing so get a bad alignment. :oops:

I want all cells in the table to be aligned to the top left.

In the example the cell named "BAD!" should be aligned like the others (to the top). The cell named "ugly code" does so, but in an ugly manner (what actually wouldn't bother me, but doesen't work for my real problem anyway :? ).

Thanks for an explaination and/or solution!

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{color}

\begin{document}
  
  \begin{tabular}{llll}
 		 \toprule
 		 	
					\noindent\begin{tabular}{l}Stuff 1 \tabularnewline Stuff 2 \end{tabular}
				&\noindent\begin{tabular}{l}\textcolor{red}{BAD!}\end{tabular}  
				&\noindent\begin{tabular}{l}Stuff 1 \tabularnewline  Stuff 2 \end{tabular} 
				&\noindent\begin{tabular}{l}Ugly code \tabularnewline ~ \end{tabular}\\[8pt]
				
			\bottomrule
	 \end{tabular}
  
\end{document}

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table in table causes bad alignment

Post by localghost »

You can try an optional positioning parameter for the inner tabular environments. See code below.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{booktabs}

\begin{document}
  \begin{tabular}{*4{l}}\toprule
    \begin{tabular}[t]{l} Stuff 1 \\ Stuff 2 \end{tabular} &
    \begin{tabular}[t]{l} \textcolor{red}{BAD!} \end{tabular} &
    \begin{tabular}[t]{l} Stuff 1 \\ Stuff 2 \end{tabular} &
    \begin{tabular}[t]{l} Ugly code \\ \end{tabular} \\ \bottomrule
  \end{tabular}
\end{document}

Best regards
Thorsten
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Table in table causes bad alignment

Post by CrazyHorse »

Code: Select all

\documentclass{article}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{makecell}
\renewcommand\cellalign{lt}

\begin{document}
 
\begin{tabular}{llll}\toprule
\makecell{Stuff 1 \\ Stuff 2 }
  & \makecell{\textcolor{red}{GOOD!}} 
  & \makecell{Stuff 1 \\  Stuff 2 }
  & \makecell{Ugly code \\ ~ }\\[8pt]\bottomrule
    \end{tabular}
 
\end{document}
Herbert
zer0nimo
Posts: 12
Joined: Wed Jul 29, 2009 3:20 am

Re: Table in table causes bad alignment

Post by zer0nimo »

Thanks to both of you!

The first solution is that simple, that I really should have got it on my own :(

Instead of [t] I've used [h!], what now got clear to me doesn't really make sense!


The second solution is a little bit more elegant and I will use this option for future work. It makes the handling of generated inputs into a tabular much easier!

Regards, Erik
Post Reply