3

I want to produce a table-like structure but preceeded by a single word on the left, like so:

variable descriptions

Here is what I tried:

\begin{minipage}[t]{\textwidth}
Here \\
\begin{tabular}{ccl}
$n$    & --- & the number of the term in the sequence---positive integer or zero;\\
$N$    & --- & value of the $n$-th term of the sequence $\left\{ F_n \right\}$; \\
$F(n)$ & --- & value of the $n$-th term of sequence $\left\{ F_n \right\}$ as a function of its number---lower index $n$.
\end{tabular}
\end{minipage}

and the result (of course my lines don't even wrap around - I was going to tackle that next):

my attempt

What am I doing wrong here (for minipage positioning at least)?

2
  • Why don't you include the word (in this case, "Here") as the upper-left most table entry, and have blank entries below it? Jul 2, 2013 at 17:45
  • That just feels "dirty" Jul 2, 2013 at 18:01

2 Answers 2

4

The Here could be put into a first column. The text can be wrapped by using p columns. However p columns require a width. Package tabularx provides X columns that are p columns that automatically use the available space.

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}[t]{@{}lccX@{}}
Here
& $n$    & --- & the number of the term in the sequence---positive integer or zero;\\
& $N$    & --- & value of the $n$-th term of the sequence $\left\{ F_n \right\}$; \\
& $F(n)$ & --- & value of the $n$-th term of sequence $\left\{ F_n \right\}$ as a function of its number---lower index $n$.
\end{tabularx}
\end{document}

Result

Remarks:

  • The minipage is no longer necessary.
  • @{} removes the space \tabcolsep at the left and right hand sides of the table.

Variant with nested tables

If you do not want to clobber the original table with surrounding text, tabularx can also be nested:

\documentclass[a5paper]{article}
\usepackage{tabularx}
\usepackage{array}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}[t]{@{}lX@{}}
Here &
  {%
    \begin{tabularx}{\linewidth}[t]%
      {@{}>{$}c<{$} >{\hangindent=1em \hangafter=1 is the }X@{}}
    n    & number of the term in the sequence---positive integer or zero;\\
    N    & value of the $n$-th term of the sequence $\left\{ F_n \right\}$; \\
    F(n) & value of the $n$-th term of sequence $\left\{ F_n \right\}$ as a function of its number---lower index $n$.
    \end{tabularx}%
  }
\end{tabularx}
\end{document}

Result

Remarks:

  • The inner tabularx needs to be enclosed in curly braces.
  • The word here is aligned with the first row of the inner table, if [t] is given for the inner tabularx. If lines are used, then check out \firsthline of package array. Otherwise the baseline of Here would be aligned with the top \hline.
  • X column provide \linewidth with the width of the column.
  • The example shows, how package array can help for automatic insertions in table cells. Math mode is set for the first column and the words is the are added to the second column.
  • For better visibility for this version without dash I have indented the followup lines of a table row by 1em (\hangindent=1em \hangafter=1).
4
  • When you say "text is wrapped in p columns" - where is the p in your code? Sorry, but I don't see it. Jul 2, 2013 at 18:07
  • @drozzy: p columns require the specification of a width. tabularx provides a X column specifier; X columns are p columns with a width that fills the available space. Jul 2, 2013 at 18:19
  • Oh I see! I am curious, why does minipage not work? Why can't i have the word "Here" in the left minipage and the table in the righ? Jul 2, 2013 at 18:20
  • @drozzy: Of course, also wrapping the whole thing in a minipage would work, but for what purpose? Also you can put all in one text line Here~\begin{tabular}[t]..., but then you do not know the available space for the p column or the available space for tabularx. Jul 2, 2013 at 18:24
3

If page-breaking is not a concern, then tabularx can help here:

enter image description here

\documentclass{article}
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
Here is some text before.

\noindent
\begin{tabularx}{\linewidth}{@{}ll@{ --- }X@{}}
  Here
  & $n$ & the number of the term in the sequence---positive integer or zero; \\
  & $N$ & value of the $n$-th term of the sequence $\{ F_n \}$; \\
  & $F(n)$ & value of the $n$-th term of sequence $\{ F_n \}$ as a function of its number---lower index~$n$.
\end{tabularx}

Here is some text after.
\end{document}

I've added the text boundary border (using showframe, even though it's not included in the code above). Note the difference in using \noindent. This may not be applicable.

3
  • Thanks. Does it do text-wrapping? Jul 2, 2013 at 18:03
  • @drozzy: Yes - the X-column is a variable-width column that wraps its contents. It expands until \linewidth (the first argument to tabularx) is reached. The use of @{} removes the column padding on either side so that the table is flush left/right. Also @{ --- } automatically inserts the --- between columns two and three.
    – Werner
    Jul 2, 2013 at 18:06
  • 1
    @drozzy: You can still use tabular. tabularx is only helpful if you have a variable-width column. If not, then you can use p{<len>} and you don't need to supply the table width.
    – Werner
    Jul 2, 2013 at 18:16

You must log in to answer this question.

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