TransWikia.com

Text doesn't fit in column

TeX - LaTeX Asked on January 14, 2021

This is my document:

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[landscape, margin=0.5in]{geometry}

title{ABC}

begin{document}

maketitle

section{First}
begin{center}
        begin{tabular}{|*{8}{c|}}
            textbf{A} &  
            textbf{B} &  
            textbf{C} &  
            textbf{D} &
            textbf{E} &               
            textbf{F} & 
            textbf{G} & 
            textbf{H}
        hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It' too long, it's too long, it's too looooooooooooooooooooooog
        end{tabular}
end{center}
end{document}

Overfull hbox (2099.37712pt too wide)
It’s possibile to have multiple lines in a column box (double slash doens’t work)?
Like:

it' too long, it's too long,  
it's too looooooooooooooooooooooog

One Answer

For automatic linebreaks in columns, use the fixed width p column type with an appropriate width argument instead of c which itself it alswys as wide as its widest entry. In the following MWE, I also added >{raggedrightarraybackslash}(needs the array package) to make sure, the contents in this specific cell are right aligned instead of justified, which is the default alignment in p type columns.

enter image description here

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[landscape, margin=0.5in]{geometry}
usepackage{array}
title{ABC}

begin{document}

maketitle

section{First}
begin{center}
        begin{tabular}{|*{7}{c|}>{raggedrightarraybackslash}p{5.5cm}|}
            textbf{A} &  
            textbf{B} &  
            textbf{C} &  
            textbf{D} &
            textbf{E} &               
            textbf{F} & 
            textbf{G} & 
            textbf{H}
        hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It' too long, it's too long, it's too looooooooooooooooooooooog
        end{tabular}
end{center}


begin{center}
        begin{tabular}{|*{7}{c|}>{raggedrightarraybackslash}p{5.5cm}|}
            textbf{A} &  
            textbf{B} &  
            textbf{C} &  
            textbf{D} &
            textbf{E} &               
            textbf{F} & 
            textbf{G} & 
            textbf{H}
        hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It' too long, it's too long,newline it's too loooooooooooooooooooog
        end{tabular}
end{center}
end{document}

The makecell package and its eponymous command could also be a useful tool:

enter image description here

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[landscape, margin=0.5in]{geometry}
usepackage{makecell}
title{ABC}

begin{document}

maketitle

section{First}
begin{center}
        begin{tabular}{|*{8}{c|}}
            textbf{A} &  
            textbf{B} &  
            textbf{C} &  
            textbf{D} &
            textbf{E} &               
            textbf{F} & 
            textbf{G} & 
            textbf{H}
        hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            makecell[lt]{It' too long, it's too long, it's too looooooooooooooooooooooog}
        end{tabular}
end{center}

end{document}

If you want to get automatic linebreaks inside of a table cell while maing sure, the table is exactly as wide as te textwidth, use the X type column from the tabularx package inside of a tabularx environment:

enter image description here

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[landscape, margin=0.5in]{geometry}
usepackage{tabularx}
title{ABC}

begin{document}

maketitle

section{First}

        begin{tabularx}{textwidth}{|*{7}{c|}>{raggedrightarraybackslash}X|}
            textbf{A} &  
            textbf{B} &  
            textbf{C} &  
            textbf{D} &
            textbf{E} &               
            textbf{F} & 
            textbf{G} & 
            textbf{H}
        hline
            It's ok & 
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It's ok &
            It' too long, it's too long, it's too looooooooooooooooooooooog It' too long, it's too long, it's too looooooooooooooooooooooog It' too long, it's too long, it's too looooooooooooooooooooooog
        end{tabularx}


end{document}

Answered by leandriis on January 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP