1

I am not an expert in LaTeX. Thus, the question may sound trivial. I am using the tabbing environment, and I have long lines to wrap. Thus, I am using the \tabfill command in order to do so.

\newcommand\tabfill[1]{%\dimen@\linewidth%
\advance\dimen@\@totalleftmargin%
\advance\dimen@-\dimen\@curtab%
\parbox[t]\dimen@{#1\ifhmode\strut\fi}%
% or, to avoid stretching:
% \parbox[t]\dimen@{\raggedright #1\ifhmode\strut\fi}%
}

The only problem that I have with this command is that the text inside the \tabfill box is aligned to the left margin. I would like that when this text is wrapped (since it is inside a tabbing environment) it is also indented in the rows following the first. Any idea about how to modify this tabfill command in order to achieve this goal? Or any other solution?

Example of what I am looking for:

Column 1                Column 2
bla bla                 bla bla bla bla bla bla bla bla bla bla bla bla
                        bla bla bla bla
bla bla                 bla bla

Code (generating no indent):

\begin{tabbing}
\hspace{3.1cm} \= \kill
Column 1 \> Column 2\\
bla bla \> \tabfill{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}\\
bla bla \> \tabfill{bla bla}
\end{tabbing}

Does it make sense?

migrated from stackoverflow.com Dec 29 '13 at 11:08

This question came from our site for professional and enthusiast programmers.

1

This is what I get from your original code (the first setting to \dimen@ uncommented):

\documentclass{article}
\makeatletter
\newcommand\tabfill[1]{%
  \dimen@\linewidth
  \advance\dimen@\@totalleftmargin
  \advance\dimen@-\dimen\@curtab
  \parbox[t]\dimen@{#1\ifhmode\strut\fi}%
}
\makeatother

\textwidth=.75\textwidth % just to make wrapping more evident

\begin{document}
\begin{tabbing}
\hspace{3.1cm} \= \kill
Column 1 \> Column 2\\
bla bla \> \tabfill{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}\\
bla bla \> \tabfill{bla bla}
\end{tabbing}
\end{document}

enter image description here

Let's add a \leftskip setting:

\documentclass{article}
\makeatletter
\newcommand\tabfill[1]{%
  \dimen@\linewidth
  \advance\dimen@\@totalleftmargin
  \advance\dimen@-\dimen\@curtab
  \parbox[t]\dimen@{%
    \leftskip=2em\hspace*{-2em}#1\ifhmode\unskip\nobreak\strut\fi}%
}
\makeatother

\textwidth=.75\textwidth % just to make wrapping more evident

\begin{document}
\begin{tabbing}
\hspace{3.1cm} \= \kill
Column 1 \> Column 2\\
bla bla \> \tabfill{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}\\
bla bla \> \tabfill{bla bla}
\end{tabbing}
\end{document}

enter image description here

If you don't plan using very complicated things inside the argument to \tabfill such as itemized or enumerated lists, this is the simplest solution. If you want to add \raggedright, place it in front of \leftskip.

  • If the argument to \tabfill contains real words with some length, as e.g. Include longs words like extracurricular rather than bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla, you'll notice a very poor result with respect to justification and hyphenation, in that the distance between each word is much too large, and no hyphenation occurs. Any way to fix that problem? – Sverre Nov 4 '14 at 16:58
  • @Sverre Try \RaggedRight (before the setting of \leftskip); you need \usepackage{ragged2e} for that command. – egreg Nov 4 '14 at 17:00
  • It fixes the interword space issue, but it doesn't lead to hyphenation where it should. As in my example sentence, you'd expect extra-curricular, but instead you get a lot of white space at the end of the first line, almost equal to the length of the word extracurricular. That is, instead of hyphenating the word, it just pushes the entire word to the next line. – Sverre Nov 4 '14 at 17:17
  • Is there something in your definition of tabfill that prevents hyphenation? – Sverre Nov 4 '14 at 17:19
  • 1
    @Sverre If I add \RaggedRight and try \tabfill{bla bla bla bla bla bla bla extracurricular bla bla bla}, I get “extracurric-ular“ with hyphenation. The same exact code, with \RaggedRight\leftskip instead of \leftskip (and \usepackage{ragged2e}. Please, ask a new question if you can't solve it. – egreg Nov 4 '14 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.