Graphics, Figures & TablesTable with Column filling the remaining Width

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am

Table with Column filling the remaining Width

Post by LavaTyper »

Greetings.

How do I design a two-column table with paragraphs such that I fix the first column width, but I set the second column width to fill the remainder of the page width?

Also: How can I change this table width such that, for example, I can indent the left and right side of this table by 0.5 inches?

I have been searching on the internet for the past two days for solutions for my specific variation in using this kind of table, and I have not found any solutions for any kinds of tabular environments or people posting about this question. I went through the beginner guides in the Rules section, and those guides did not help. I tried searching this form for possible solutions, but none of the 117 matches that I ended up with were about my specific table construction.

So, how do I make a two-column table such that the second column fills the remainder of the page, or specified table width?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table with Column filling the remaining Width

Post by localghost »

What you are after can be done by e. g. the tabularx package. You can give a calculated width by \dimexpr\textwidth-1in that leaves the desired half inch on both sides of the table. An appropriate formatting for captions above tables is done by the caption package.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{booktabs,tabularx}

\captionsetup{
  font=small,
  labelfont=bf,
  tableposition=top
}

\begin{document}
  \begin{table}[!ht]
    \caption{A table with a fixed width column and one that fills the remaining horizontal space.}
    \centering
    \begin{tabularx}{\dimexpr\textwidth-1in}{p{1in}X}\toprule
      Table Head  & Table Head \\\midrule
      Some Text for Explanation & The quick brown fox jumps over the lazy dog. \\ \bottomrule
    \end{tabularx}
  \end{table}
\end{document}
For details please refer to the manuals of the involved packages. For tables like this the quite new tabu package would be an alternative (despite its awful manual).


Best regards and welcome to the board
Thorsten
LavaTyper
Posts: 69
Joined: Sat Feb 11, 2012 2:38 am

Table with Column filling the remaining Width

Post by LavaTyper »

I was able to get this to work.

Also, a follow-up question:

I want to include a PDF (which contains an image) in a LaTeX document, but whenever I demand that the image width span the full page, the image either ends up on the last page, or I need to make the image small (like, 1 inch borders on either side).

I want to keep the image in the PDF, since it's mostly text and vector graphics, and I need the resolution. How do I force the image to span the full page width (and maybe even larger?

Code: Select all

\begin{figure}[!h]
\begin{center}
\includegraphics[width=17cm]{MyPDFVectorGraph}
\end{center}
\end{figure}
doesn't work, and

Code: Select all

\begin{figure}[!h]
\begin{center}
\includegraphics[width=\textwidth]{MyPDFVectorGraph}
\end{center}
\end{figure}
doesn't work. I tried changing "!h" to "h" and that didn't work.
Last edited by Stefan Kottwitz on Wed Feb 15, 2012 9:30 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table with Column filling the remaining Width

Post by localghost »

Andrej wrote:[…] I want to include a PDF (which contains an image) in a LaTeX document, but whenever I demand that the image width span the full page, the image either ends up on the last page, or I need to make the image small (like, 1 inch borders on either side). […]
This is not really a follow-up questions since it is not related at all to the original question. You should not mix different topics in one thread and therefore open a new one.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

Table with Column filling the remaining Width

Post by Stefan Kottwitz »

The positioning option h (also as !h), allowing "here" is usually not sufficient. This way you don't allow floating to the top or to the bottom of a page. Where should it go if it happened, that "here" near the end of a page would not be sufficient space left?

Regarding the width, you can put it centered within a box of the same width as the text:

Code: Select all

\begin{figure}[!htbp]
  \makebox[\textwidth]{\includegraphics{MyPDFVectorGraph}}
\end{figure}
\makebox centers by default. In general, better use \centering with a figure environment, not \begin{center} ... \end{center}, because that causes additional vertical space.

Stefan
LaTeX.org admin
Post Reply