What's the best way to create a table with a lot of data (text) ?
- 14,215
- 165
2 Answers
Welcome to tex.se! Obviously this a very open question. Some decisions about the design certainly don't have a blanket solution and have to be reassessed depending on the content of the table and the goal you are trying to achieve with it: Do you want centered text? Rules or spaces separating rows or columns? Should the cells be somehow otherwise distinguished from each other, for example with a background colour? Does the amount of text vary a lot from cell to cell? Is a table really the best way of displaying this text? Is it going to be displayed on a poster, in an article, etc.?
Like in other aspects of typography, there is hardly a single best way for all possible situations.
But here's one possible example nontheless:
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\noindent \begin{tabularx}{\textwidth}{@{} l X X X @{}}
\toprule
\textbf{Klasse} & \textbf{Konfidesialitet} & \textbf{Integritet} & \textbf{Tilgjenglighet} \\
\midrule
\textbf{Niva 1}
& Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
& Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
& Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. \\
\textbf{Niva 2}
& Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
& Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
& Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. \\
\bottomrule
\end{tabularx}
\end{document}
There are of course many ways you could further improve or change this example (for example using tabulary instead of tabularx)... Maybe also have a look at Beautiful table samples or similar threads and see if you find something that suits you there.
- 743
-
Thanks for the warm welcome! It's a very open question indeed, this looks like a great starting point and thanks for the reference to "Beautiful table samples". Seams like a perfect place to find out more! – Petter Östergren Feb 17 '20 at 15:59
One solution with tabulary:
\documentclass{article}
\let\bf\bfseries
\usepackage{array,geometry,tabulary,booktabs,lipsum,microtype}
\begin{document}
\renewcommand\arraystretch{2}
\begin{tabulary}{\linewidth}{>{\bf}l*3{>{\parskip1em}L}}\toprule
Klasse &
\bf FooFooFoo &
\bf FooFoo &
\bf FooFooFoo \\\midrule
Niv\.a 1 &
\lipsum[1][1-2]\par\lipsum[2][1-3] &
\lipsum[3][1-3]\par\lipsum[4][1-3] &
\lipsum[5][1-3]\par\lipsum[5][4-5]\\\cmidrule{2-4}
Niv\.a 1 &
\lipsum[6][1-2]\par\lipsum[7][1-8] &
\lipsum[8][1-2]\par\lipsum[9][1-2] &
\lipsum[10][1-3]\par\lipsum[11][1-3]\\\bottomrule
\end{tabulary}
\end{document}
- 80,769
-
-
@Zarko I am using really
\bfseries, not\bf(see line 2). About\addlinespace, indeed, in general. But for this case I wanted to avoid confusion about the paragraph skips between and within cells. – Fran Feb 17 '20 at 14:04 -
I see now, however, I will not do this (redefine TeX command with LaTeX's one). – Zarko Feb 17 '20 at 14:13
-
-
-
Are there any possibility to scale table width (let's say I want it to be 80% of total page width)? Which param could I edit, cant figure it out. – Petter Östergren Feb 17 '20 at 20:39
-
1@PetterÖstergren Change
\linewidthby0.8\linewidth(you can omit the zero). – Fran Feb 17 '20 at 20:52 -
@Fran: Could you prehapse go into a bit more depth on what the different args in
{tabulary}{args..}. I tried to extend this into a 5 column (without \bf the first col)Heres a screenshot https://imgur.com/a/T8TlVGF I don't understand why col 1 dont wrap
– Petter Östergren Feb 17 '20 at 23:39 -
1@PetterÖstergren
tabularycan use thel,candrcolumns of the basictabularenvironment , with cells of unbreakable single lines andL,C,Rcolumns that can have breakable lines and even paragraphs. There are more column types: p, J, m, b ... Runtexdoc lshort(see pages 34-37) and thentexdoc array(see pages 1--3) andtexdoc tabulary(see pages 1--4). – Fran Feb 18 '20 at 01:34



tabularxpackage. – leandriis Feb 17 '20 at 13:00tabulary(similar totabularx, but allow desigual widths and any type of alignment) – Fran Feb 17 '20 at 13:03