Graphics, Figures & TablesLarge cell content in table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
marole
Posts: 2
Joined: Tue May 05, 2009 11:53 am

Large cell content in table

Post by marole »

Hi,

I have a large table with some columns containing quite a lot of text. In each cell I would like to left align (which isn't a problem) as well as manually determine the line break within that cell. Is this possible? It is sort of a table in a table cell that I want. I attach an example where I would like to be able to break the line within the cell after each colon:

Code: Select all

\documentclass[a4paper,10pt,onecolumn]{article}
\usepackage{array}					
\newcolumntype{x}[1]{>{\raggedright\hspace{0pt}}p{#1}}
\usepackage{booktabs}				
\begin{document}

\begin{table}
\caption{Can I do table within table?}
    \begin{center}
    \small{
    \begin{tabular}{x{1.3cm} x{1.4cm}  x{4.2cm} x{4.2cm}}\\\toprule[.4mm]
    	Colunm 1 &Column2  &Column3 &Column4 \tabularnewline\midrule
        
        entry &entry & 5\%: input for 5\% 20\%: input for 20\% 50\%: input for 50\%  & 5\%: result for 5\% 20\%: result for 20\%	50\%: result for 50\%\tabularnewline\midrule
        
        entry &entry & 5\%: other input for 5\% 20\%: other input for 20\% 50\%: other input for 50\%  & 5\%: other result for 5\% 20\%: other result for 20\%	50\%: other result for 50\%\tabularnewline	    	
	    	
    \bottomrule[.4mm]                                                                           
    \end{tabular}
 		}
   \end{center}                                                 
\end{table}

\end{document}
I can't just wrap the cell contents either, because each row will have different appropriate widths as seen in the example. Anyone have any ideas? Or at least any proper word for this to google?

Thankful for any help!
Attachments
LatexHelp.pdf
(13.34 KiB) Downloaded 341 times

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

Large cell content in table

Post by localghost »

I'm not really sure if I understood you right regarding the line break. Of course a table within a table is possible. Consider the following modification of your example.

Code: Select all

\documentclass[10pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{array,booktabs}

\newcolumntype{x}[1]{>{\raggedright}p{#1}}
           
\begin{document}
  \begin{table}[!ht]
    \centering
    \caption{Can I do table within table?}
    \small
    \begin{tabular}{x{1.3cm}x{1.4cm}x{4.2cm}x{4.2cm}} \toprule
      Column1 &Column2  &Column3 &Column4 \tabularnewline\midrule
      entry &entry & 
      \begin{tabular}[t]{@{}r@{: }l@{}}
        5\% & input for 5\% \\
        20\% & input for 20\% \\
        50\% & input for 50\%
     \end{tabular} & 
     \begin{tabular}[t]{@{}r@{: }l@{}}
       5\% & input for 5\% \\
       20\% & input for 20\% \\
       50\% & input for 50\%
     \end{tabular} \tabularnewline\midrule
    entry &entry & 5\%: other input for 5\% 20\%: other input for 20\% 50\%: other input for 50\%  & 5\%: other result for 5\% 20\%: other result for 20\%   50\%: other result for 50\%\tabularnewline \bottomrule
    \end{tabular}
  \end{table}
\end{document}
I only modified the first line after the table head. If the line break doesn't match your ideas, you can simply adapt the code. I think this makes the new column type superfluous because you can use a simple "l" type column.


Best regards and welcome to the board
Thorsten¹
marole
Posts: 2
Joined: Tue May 05, 2009 11:53 am

Re: Large cell content in table-fixed!

Post by marole »

Thank you very much! Your help solved my table-within-table problem.
Thanks for a good forum!
Post Reply