Re: Wrap a single long word in a table?
- From: Enrico Gregorio <gregorio@xxxxxxxxxxxxx>
- Date: Tue, 13 Mar 2007 22:03:40 +0100
<"davejohansen@xxxxxxxxx"> wrote:
I am trying to get LaTeX to break a single long word in a table
automatically, but I haven't been able to get it to work. At the
bottom of this post is a minimal example of what I am doing. I
basically want "really_long_var_name_that_just_keeps_going" to break
and wrap to the next line. Is there any way to do this automatically?
Thanks,
Dave
\documentclass{article}
\usepackage[top=1in,left=1in,right=1in,bottom=1in]{geometry}
\newenvironment{inputtable}[1]
{
\begin{table}
\centering
\caption{#1 Inputs}
\begin{tabular}{|p{1.25in}|p{4.0in}|p{0.75in}|}
\hline
\makebox[1.25in][c]{\textbf{Symbol}} &
\makebox[4.0in][c]{\textbf{Description}} &
\makebox[0.75in][c]{\textbf{Units}} \\
\hline
}
{
\end{tabular}
\label{tab:}
\end{table}
}
\newcommand{\addinput}[3]{#1 & #2 & #3 \\ \hline}
\begin{document}
\begin{inputtable}{Foo}
\addinput{short\_var\_name}{This is a short description}{radians}
\addinput{really\_long\_var\_name\_that\_just\_keeps\_going}
{This is a really long description that should wrap in the space
that it's provided}
{meters}
\end{inputtable}
\end{document}
This is what I call a horror. I don't understand where
short\_var\_name & This is a short description & radians \\
\hline
is less clear or less easy to input than
\addinput{short\_var\_name}{This is a short description}{radians}
unless you are doing experiments with the formatting of the entries
which can be done by using the array package extensions to tabular.
Moreover you are repeating the same label for every table of this
kind.
For the problem, if you are willing to break at the underscore,
then something like
\usepackage{array}
\let\originalus\_
\newcommand{\changeus}{\renewcommand{\_}{\originalus\hspace{0pt}}}
\newenvironment{mytable}[1]
{%
\begin{tabular}{|>{\changeus\raggedright}p{1.25in}|p{4.0in}|p{0.75in}|}
\hline
\multicolumn{1}{|c|}{\textbf{Symbol}} &
\multicolumn{1}{c|}{\textbf{Description}} &
\multicolumn{1}{c|}{\textbf{Units}} \\
\hline
}
{\end{tabular}}
could be useful. Notice that you don't need those \makebox commands.
You can then input your table as
\begin{table}[htbp]
\centering
\caption{Foo Inputs}\label{tab:foo}
\begin{mytable}
short\_var\_name & This is a short description & radians\\
really\_long\_var\_name\_that\_just\_keeps\_going &
This is a really long description that should wrap in the space
that it's provided &
meters\\
really\_big\_preposterous\_variable\_name\_that\_just\_keeps\_going &
This is a really long description that should wrap in the space
that it's provided &
meters\\
\hline
\end{mytable}
\end{table}
I believe that this makes the input clearer and easier to search. The
\raggedright is essential, or LaTeX will not have very good points for
breaking the line.
Explanation of the trick: we save the meaning of \_ and define a
command which redefines it to the original meaning followed by a zero
space (which permits LaTeX to split the line). In every cell of the
first column we redefine the \_ command and issue \raggedright.
But probably something like
\newenvironment{mytable}[1]
{\renewcommand{\arraystretch}{1.2}
\begin{tabular}{>{\changeus\raggedright}p{1.25in}p{4.0in}p{0.75in}}
\toprule
\multicolumn{1}{c}{\textbf{Symbol}} &
\multicolumn{1}{c}{\textbf{Description}} &
\multicolumn{1}{c}{\textbf{Units}} \\
\midrule
}
{\bottomrule\end{tabular}}
after loading the booktabs package and deleting all \hline commands
will look better. Change the 1.2 to suit your preferences.
Ciao
Enrico
.
- Follow-Ups:
- Re: Wrap a single long word in a table?
- From: davejohansen@xxxxxxxxx
- Re: Wrap a single long word in a table?
- References:
- Wrap a single long word in a table?
- From: davejohansen@xxxxxxxxx
- Wrap a single long word in a table?
- Prev by Date: Re: using \; outisde of mathmode
- Next by Date: Re: table of contents problem with longtable and bibliography
- Previous by thread: Wrap a single long word in a table?
- Next by thread: Re: Wrap a single long word in a table?
- Index(es):
Relevant Pages
|
Loading