1

I am trying to have a fill in the blank paragraph inside of a box. I've been using mdframed with great success, but the underline blank doesn't wrap inside of the box. I'm newer to Latex; I've tried using the mdframed documentation and tried Why does underlined text not get wrapped once it hits the end of a line ? and Underlined blank that wraps (the latter being pretty complex for my abilities right now). Thank you for your help!

\documentclass{article}

\usepackage{mdframed}

\newcommand{\hard}[1]    {\unskip\underline{\hspace{#1}}\ignorespaces}

\begin{document}

\begin{mdframed}
The population in a study refers to the \hard{2in} \\or \hard{2.5in}.  A sample is a (typically small) \hard{2in} from whom or about which data are gathered to learn about \hard{2in}.  If the sample is selected carefully, so it is \hard{1.5in} of (\hard{2in}) the population, you can learn \hard{2in}. The number of observational units studied in a sample is the \hard{1in}.
\end{mdframed}

\end{document}
  • It 'wraps' well with tcolorbox instead of mdframed, however. If I remember correctly, \underline can't wrap. Try \underline{A very long long long long long long long long long long long long long long long long long long line} for example. It should leak into the right margin for your textwidth settings – user31729 Sep 8 '17 at 19:39
  • The \unskip shifts the line too much to the left, in my point of view – user31729 Sep 8 '17 at 19:45
  • I replaced mdframed with tcolorbox and you're right, it does wrap inside of the box created. Cool! However, the box doesn't seem to fill the width of the page, which isn't ideal. I like what that package seems to be doing though, so thank you for the tip. But overall, this doesn't quite answer my question. – Jenni Sep 8 '17 at 20:06
  • A tcolorbox environment does always use the \linewidth (which is the \textwidth usually in a normal page), unless some explicit width statement is used. In my opinion, tcolorbox is the more powerful package. Try \begin{tcolorbox}[enhanced,sharp corners,boxsep=0pt] ... \end{tcolorbox} – user31729 Sep 8 '17 at 20:08
2

Christian Hupfer answered my question but I have no way to mark it as answered. I ended up going with the tcolorbox package which, to be honest, provides a nice contrast in the notes I'm typing up.

I also played around with the justifying from the tcolorbox documentation, got rid of \unskip and \ignorespaces and the package is working very nicely. I really appreciate the help.

\documentclass{article}

\usepackage{tcolorbox}

\newcommand{\hard}[1]    {\underline{\hspace{#1}}}

\begin{document}

\begin{tcolorbox}[halign=left]
The population in a study refers to the \hard{2in} \\or \hard{2.5in}.  A sample is a (typically small) \hard{2in} from whom or about which data are gathered to learn about \hard{2in}.  If the sample is selected carefully, so it is \hard{1.5in} of (\hard{2in}) the population, you can learn \hard{2in}. The number of observational units studied in a sample is the \hard{1in}.
\end{tcolorbox}

\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.