0

Here is a command I have:

\newcommand{\numbox}[2]{$^{\circled{#1}}${\fbox{#2}}}

What it does is boxing and numbering a text. However I for the box to break nicely across lines. In command \fbox{text} the text may stick out of the margins if the line is full. However I want to write a conditional for this case. Such as:

until text finished
after every word: 
   if there is \linebreak:
       end \fbox
       continue text with \fbox
       

enter image description here enter image description here

In above I added Images!

%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%

I used multiline colored box but as I said, since sentences are small it doesn’t look that nice tbh. Here is the image:

enter image description here

14
  • Welcome to TeX.SE. I'm having trouble following your question. I understand your \numbox definition, but everything after that is harder to understand. What conditional are you wanting? Could you create a MWE that shows where your conditional should do something different?
    – Teepeemm
    Oct 14, 2021 at 13:58
  • 3
    If I understand correctly, you want breakable \fboxes?
    – plante
    Oct 14, 2021 at 14:07
  • 1
    you could look at soul or ulem for breakable highlighting but don't you really just want \fbox{\parbox{.9\textwidth}{ text allowing line breaking in a box}} ? Oct 14, 2021 at 14:26
  • @plante actually yes. But I want to use it in \newcommand :) Oct 14, 2021 at 15:17
  • @davidcarlisle I am going to check it thanks :) Oct 14, 2021 at 15:18

2 Answers 2

1

Not an answer, but just a suggestion: tcolorbox

enter image description here

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum} % for dummy text
\newtcbox[auto counter]{\solution}[1][]{%
fonttitle=\bfseries\sffamily,
tcbox raise=-4mm,
grow to left by=-90pt, 
attach boxed title to top left={xshift=-90pt,yshift=-20pt}, 
enhanced,
tcbox width=auto limited, 
title= Solution ~\thetcbcounter #1}
\begin{document}
\lipsum[2]
\solution{\lipsum[1][1]}
\solution{\lipsum[3][1]}
\solution{\lipsum[3][1-5]}
\lipsum[4]
\end{document}
0

Also not an answer, but to my mind one of the most useful source: https://tools.ietf.org/doc/texlive-doc/latex/tcolorbox/tcolorbox.pdf

You must log in to answer this question.

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