1

My document is mainly made up of justified text, but with sections made of two column & left flushed text (actually verses). Below is a MWE.

As in Flush a left-flushed box right, I want the text of the second column to be:

  • left flushed, and
  • that the longest line of this secund colum is also left-flushed and right-aligned ?

Here, a shema, where | are the limits of text area:

|Some normally justi-|
|fied text.          |
|                    |
|Foo            Fus  |
|Bar            Roooh|<- the right end of the longest line matches the text-area limit
|Baz            Da!  |

As I want the solution to be generic, and as I don't necessary know the number of lines of the "two-columned" text (there could be a pagebreak in it), I found the solution suggested in the thread (and in its duplicate) made of a tabular+\hfill not convinient.

Question: Is there a simple way to stretch the \columnsep dimension used in the multicols environment, as an \hfill would do?


\documentclass{scrartcl}

    \usepackage{multicol}
    \usepackage{lipsum}

\begin{document}
    \lipsum[1]

    \begin{multicols}{2}
        \noindent
        Foo foo foo\newline
        Bar, barbar\newline
        Bazbazbaz baz babaz

        \noindent
        Fusss fus,\newline
        Roh\newline
        Daaaa !
    \end{multicols}

    \noindent\lipsum[2]
\end{document}
  • varwidth package might help. – Manuel Dec 2 '15 at 21:30
3

Since you are manually breaking the lines anyway it is easiest to box them (otherwise if you let TeX's normal paragraph breaker break the paragraph in to lines, they will all be full width even if they have short text).

enter image description here

If each line is its natural width you just have to unbox and re-box the right hand column so that the column is set to the width of its content then the existing glue that multicols uses will push the column to the right.

\documentclass{scrartcl}

    \usepackage{multicol}
    \usepackage{lipsum}

\makeatletter
\def\mc@align@columns{%
     \process@cols\mult@gfirstbox{%
       \ifdim\dp\count@>\dimen\tw@
         \global\dimen\tw@\dp\count@ \fi
       \mc@col@status@write
       \box\count@
       \hss{\columnseprulecolor\vrule
              \@width\columnseprule}\hss}%
     \ifdim\dp\mult@rightbox>\dimen\tw@
       \global\dimen\tw@\dp\mult@rightbox \fi
     \mc@lastcol@status@write
     \vbox{\unvbox\mult@rightbox}%
}
\makeatother

\begin{document}
    \lipsum[1]

    \begin{multicols}{2}

        \hbox{Foo foo foo}
        \hbox{Bar, barbar}
        \hbox{Bazbazbaz baz babaz}

\bigskip

        \hbox{Fusss fus,}
        \hbox{Roh}
        \hbox{Daaaa !}
    \end{multicols}

    \noindent\lipsum[2]
\end{document}

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.