90

I'm making a tabular and I'd like to automatically do a like break rather than going beyond the page.

This is my tabular code:

\begin{table}[h]
\begin{tabular}{|l|l|l|}
Use Case Navn:          & \multicolumn{2}{l}{Opret Server} \\
Scenarie:               & \multicolumn{2}{l}{At oprette en server med bestemte regler som tillader folk at spille sammen. More Text more text More Text} \\
\end{tabular}
\end{table}

This is my preamble:

\documentclass[danish,a4paper,twoside,11pt]{report}
\usepackage{babel}
\usepackage[utf8x]{inputenc}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{titling}
\usepackage{color}
\usepackage{xcolor}
\usepackage{nag}
\usepackage{tabularx}

\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\}

This is how it looks right now: image

1

2 Answers 2

116

Since you've tagged the question tabularx, this is a solution with tabularx (no need for those \multicolumns)

\documentclass[danish,a4paper,twoside,11pt]{report}

\usepackage{tabularx}

\begin{document}
\begin{table}[h]
\begin{tabularx}{\textwidth}{|l|X|}
Use Case Navn:          & Opret Server \\
Scenarie:               & At oprette en server med bestemte regler som tillader folk at spille sammen. More Text more text More Text \\
\end{tabularx}
\end{table}
\end{document} 

enter image description here

The column type X takes all the space left from other columns till \textwidth or whatever you specify in the first argument.

3
  • The reasoning behind using multicolumn is that I need the tabular to be 2 cells in the upper part of the tabular and 3 cells in the lower one. Apologies for not showing you this in the original post, but this is how the tabular looks like in Word (just started studying LaTeX at school), so we need to "transform" a word document to LaTeX. Anyway, here's the tabular in word: prntscr.com/33xuog Mar 25, 2014 at 9:37
  • What should I use instead of X if I am using double column? @karlkoeller
    – alper
    May 16, 2019 at 11:29
  • How to make it ragged right instead of justified?
    – minseong
    Apr 11, 2021 at 13:26
46

One of the approaches is to use a p type column, p{dimension}:

\documentclass[a4paper]{article}
\pagestyle{empty}
\begin{document}
\begin{table}[h]
{\renewcommand\arraystretch{1.25}
\begin{tabular}{|l|l|l|} \hline
Use Case Navn:& \multicolumn{2}{l|}{Opret Server} \\ \hline\hline
Scenarie:& \multicolumn{2}{p{4cm}|}{\raggedright At oprette en server med bestemte regler som tillader folk at spille sammen. More Text more text More Text} \\ \hline
\end{tabular}}
\end{table}
\end{document}

enter image description here

3
  • 4
    You can also use \multicolumn{1}{p{4cm}|} with 1 instead of 2 columns. Then we don't need 3 columns (|l|l|l|) for a 2 column table...
    – janniks
    Nov 18, 2019 at 18:50
  • Is it possible to make the text in the first column placed in the center of the cell?
    – Ghrua
    Apr 21, 2021 at 8:12
  • 1
    @Ghrua \begin{tabular}{|c|l|l|} should help with the horizontal centering. Try multirow package for vertical centering. I've never needed an automatic way, I would probably check out the tabu package or I'd try the tikz package.
    – Malipivo
    Apr 21, 2021 at 10:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .