2

Is there an easy way to break a rule over multiple lines? I.e. for it to continue flowing just as text would, and not continuing straight through the page border?

Specifically, I'm trying to typeset questions for a test.

Here's a MWE:

\documentclass[11pt]{article}
\usepackage{enumitem}
\usepackage[left=2cm,right=2cm,bottom=2cm,top=2cm]{geometry}
\usepackage[onehalfspacing]{setspace}

\begin{document}

\begin{enumerate}[label=(\arabic*)]
\item Ap sala kemae njeuqsket jquakmdk a kameiuwma ke eiqkamk jekamska keialk
oela \rule{6cm}{0.15mm}.
\end{enumerate}

\end{document}

What I'm getting is this:

enter image description here

What I'd like to get is something like enter image description here

but with the first part of the line stretching to the end of the text width, then breaking and continuing in the next line. (The "desired" output was done by typesetting the rule with two calls to the \rule command, with a manual line break, i.e. \\ between them.)

5
  • 1
    Are you looking for something like this: tex.stackexchange.com/questions/125840/… ? My censor package's \xblackout macro breaks across lines, and can be set up as a "rule" in appearance with \censorruledepth=-.2ex and \censorruleheight=.1ex May 2, 2018 at 15:34
  • I tried using \xblackout{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} with the options you've listed in the comment (and the other post), but have run into the same problem. So, the MWE is the same as before, but \rule is replaced by \xblackout as stated earlier, and the \censorrule... options are set.
    – Potato
    May 2, 2018 at 15:48
  • The same happend when using the \underline{\phantom{text}} trick. Moreover, it appeared when using just \phantom{long-text}. Maybe it's because of the \enumerate environment?
    – Potato
    May 2, 2018 at 15:53
  • \xblackout works with text, and allows breaks between words, in the manner of \xblackout{This is the text I want blacked out}. In this sense, it may not be exactly what you want. May 2, 2018 at 16:39
  • Aaaah, sorry! I thought it would work with arbitrary text. I put "this is sample text that should be black" in the \xblackout function and it works as intended. Basically, I'm trying to keep the blank lines at about the same length, so I'll just use your package with some text "constant". That being said, I don't know how I haven't come across the topic you've linked. If you'd like to post your comment as an answer, I'll gladly accept it. Thank you!
    – Potato
    May 2, 2018 at 16:50

2 Answers 2

5

I introduce \breakablerule that takes the same parameters as \rule. It builds up the rule by using segments of length \drule, here initialized as 2pt. The last segment will likely be less than \drule in length, in order to meet the overall length goal.

\documentclass[11pt]{article}
\usepackage{enumitem}
\usepackage[left=2cm,right=2cm,bottom=2cm,top=2cm]{geometry}
\usepackage[onehalfspacing]{setspace}
\newlength\rulegoal
\newlength\drule
\setlength{\drule}{2pt}
\newcommand\breakablerule[3][0pt]{\setlength{\rulegoal}{#2}\breakableruleaux{#1}{#3}}
\newcommand\breakableruleaux[2]{%
  \ifdim\rulegoal>\drule\relax%
    \rule[#1]{\drule}{#2}\allowbreak%
    \def\next{\breakableruleaux{#1}{#2}}%
  \else
    \rule[#1]{\rulegoal}{#2}%
    \def\next{}%
  \fi 
  \addtolength{\rulegoal}{-\drule}%
  \next%
}
\begin{document}
\begin{enumerate}[label=(\arabic*)]
\item Ap sala kemae njeuqsket jquakmdk a kameiuwma ke eiqkamk jekamska 
  keialk oela \breakablerule[-3pt]{6cm}{0.15mm}.
\item Ap sala kemae njeuqsket jquakmdk a kameiuwma ke eiqkamk jekamska  
  \breakablerule{6cm}{0.15mm}.
\item Ap sala kemae njeuqsket jquakmdk a kameiuwma ke eiqkamk 
  \breakablerule{6cm}{0.15mm}.
\end{enumerate}
\end{document}

enter image description here

There is probably a way to do this directly with leaders.

3

For one-off uses, you can break the line manually using a combination of \hrulefill \\ and another \rule of fixed width:

enter image description here

\documentclass{article}

\usepackage{enumitem}
\usepackage[margin = 2cm, showframe]{geometry}
\usepackage[onehalfspacing]{setspace}

\begin{document}

\begin{enumerate}[label=(\arabic*)]
  \item Ap sala kemae njeuqsket jquakmdk a kameiuwma ke eiqkamk jekamska keialk
  oela \rule{6cm}{0.15mm}.

  \item Ap sala kemae njeuqsket jquakmdk a kameiuwma ke eiqkamk jekamska keialk
  oela \hrulefill \\
  \rule{5cm}{.4pt}.% \hrulefill has .4pt thickness
\end{enumerate}

\end{document}
1
  • This is a nice trick, but I prefer Steven's suggestion since it's more (or more easily) customisable.
    – Potato
    May 8, 2018 at 7:47

You must log in to answer this question.

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