4

I want to achieve like shown below:

enter image description here

But the only thing I can get with ulem is:

enter image description here

With the code below:

\documentclass[12pt]{report}
\usepackage{ulem}

\begin{document}
\begin{center}
  \begin{minipage}{.6\textwidth}

    \uline{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non
    vulputate neque, sit amet dictum dolor. Vestibulum auctor ante nec arcu 
    faucibus lacinia.}

    \begin{center}
      \uline{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non
      vulputate neque, sit amet dictum dolor. Vestibulum auctor ante nec arcu 
      faucibus lacinia.}
    \end{center}

  \end{minipage}
\end{center}
\end{document}
  • 1
    Welcome to TeX-SE! The fist one can be obtained by adding \hfill: \uline{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non vulputate neque, sit amet dictum dolor. Vestibulum auctor ante nec arcu faucibus lacinia.\hfill{}}. – user121799 Jun 4 '19 at 12:32
4

This solution uses \vbox to format the text and \vsplit to underline each line.

\documentclass[12pt]{report}
%\usepackage{ulem}

\newcommand{\lined}[1]% #1 = paragraph text
{\bgroup
  \setbox0=\vbox{\strut #1\strut}%
  \dimen0=0pt
  \loop\ifdim\ht0>0pt
    \dimen1=\dimexpr\ht0 - \baselineskip\relax
    \setbox1=\vsplit0 to \ht\strutbox
    \advance\dimen1 by -\ht0
    \noindent\raisebox{-\dimen0}[\ht\strutbox][\dp\strutbox]{\box1}%
    %\llap{\the\dimen0~\rule{\textwidth}{0.5pt}}% show baseline
    \advance\dimen0 by \dimen1
    \vspace{-0.2ex}\hrule\vskip 0.2ex % aesthetic tweak
  \repeat
\egroup}


\begin{document}
\begin{center}
  \begin{minipage}{.6\textwidth}
    \parindent=\bibindent
    %\huge
    \lined{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non
    vulputate neque, sit amet dictum dolor. Vestibulum auctor ante nec arcu 
    faucibus lacinia.}

    \begin{center}
      \lined{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non
      vulputate neque, sit amet dictum dolor. Vestibulum auctor ante nec arcu 
      faucibus lacinia.}
    \end{center}

  \end{minipage}
\end{center}
\end{document}

demo

  • Thanks for your help! It works fine in default font size. But when l changed to \Huge size, there comes some alignment problems. How to fix it? Imgur – Alexara Jun 4 '19 at 15:24
  • Yeah. It turns out that \vsplit is not acting consistently. It grabs 34.67912pt the first line, 29.043pt the second line, then settles down to 30pt per line. The net result is that the baseline of \box1 is not where it should be. Alas, most of my attempts to fix this result in infinite loops. – John Kormylo Jun 4 '19 at 21:32

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.