1

I am new to latex. So I am using only basic commands. I am writing my thesis, in which I have to add a lot of tables. Regarding the horizontal length of tables, I would like to have same horizental length for all tables.

Is there any command to set this?

Thanks

Jan
  • 5,293
  • 1
    Welcome to TeX.SX. You mean the table width, I assume. Please have a look on the tabularx package then –  Jan 02 '17 at 09:05
  • 1
    @Mico I'm not sure this is a dupe: the question here is about having all tables of the same width, not necessarily the text width. – Joseph Wright Jan 02 '17 at 10:20
  • 1
    @JosephWright - I would have thought that setting, say, 0.9\textwidth is a rather obvious generalization of 1.\textwidth. However, I may be wrong! I'll re-open the posting. – Mico Jan 02 '17 at 10:25
  • 1
    See the posting How to force a table into page width? for methods for setting the widths of tabular-like environments (tabular, tabular*, tabularx, etc) to \textwidth -- to the width of the page block. These methods can be adapted in obvious ways if the intended width is, e.g., 0.9\textwidth or \columnwidth. – Mico Jan 02 '17 at 10:27
  • 1
    @Mico I said I wasn't sure: perhaps see what the OP says (my impression was the other question was about tables that are too wide, whereas this one seems to me to be about tables that would naturally be narrower). – Joseph Wright Jan 02 '17 at 10:30

2 Answers2

1

To help you make use of the comment from Christian Hupfer, I will describe, what you could do, if you have no idea yourself. He recommends a package named tabularx.

So let's check this out: Go to https://www.ctan.org and search for tabularx. Then you will find exactly this package with its short description "Tab­u­lars with ad­justable-width columns". Sounds pretty much like what we're searching. So let's click on that and take a look at the package documentation.

After reading the intro and the first example, you should be able to create a table with a fixed width yourself:

\begin{tabularx}{250pt}{|c|X|c|X|}
nox
  • 4,160
  • 12
  • 26
0

As pointed in the comment, you can use the tabularx-package in your preamble.

Tabularx introduces a new column type identifier: X (that is a capital X). The X-column works pretty much the same way, an ordinary p{width}-column does. The difference is: in a p-column, you have to define the width of the column. For the tabularx you have to define the total width of your table. The X-columns are than used to make the columns that big, that the total width of the table reaches the desired value.

Here is an example:

\documentclass[12pt]{article}  

\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\begin{tabularx}{4cm}{rX}
  \toprule
  left 1 & Lorem ipsum amet dolores ingrum\\
  another line & foo bar baz brave check hat dot ddot\\
  \bottomrule
\end{tabularx}

%% Same table somewhat wider
\begin{tabularx}{6cm}{rX}
  \toprule
  left 1 & Lorem ipsum amet dolores ingrum\\
  another line & foo bar baz brave check hat dot ddot\\
  \bottomrule
\end{tabularx}

%% And even wider
\begin{tabularx}{8cm}{rX}
  \toprule
  left 1 & Lorem ipsum amet dolores ingrum\\
  another line & foo bar baz brave check hat dot ddot\\
  \bottomrule
\end{tabularx}

\end{document}  

And its result:

enter image description here

Jan
  • 5,293