5

It's all in the subject. I used all kinds of boxes in a towcolumn article, but whenever the boxed text is long enough, the box happily continues into the other column!

Is there a "smart" box that "follows" the text, like the blue one aroung URLs ? Sample document:

\documentclass[10pt,twoside,twocolumn,english]{article} 
\begin{document}  
\fbox{Alpha particles (named after and denoted by the first letter in the
Greek alphabet) consist of two protons and two neutrons bound
together.
This means that an  particle is a helium nucleus. }
\end{document}
  • Welcome to TeX.SX! Would you like to explain better what you mean with "boxed text"? – egreg Jun 9 '12 at 10:39
  • Maybe provide a minimal working example. meta.tex.stackexchange.com/questions/228/… – Afr Jun 9 '12 at 10:39
  • 1
    \mbox is indivisible by design. – egreg Jun 9 '12 at 10:45
  • @donc_oe: added a sample. – ExpertNoob Jun 9 '12 at 10:50
  • 2
    @ExpertNoob I don't think this is a particularly good way to emphasize some text. To be honest, I find it a bad way to emphasize text. – egreg Jun 9 '12 at 10:52
6

This is too long for a comment: I think that an image will convince you desisting from this project.

enter image description here

The result is undoubtedly awful.


On the serious side, here's a simple way to frame something in a better fashion.

\documentclass[10pt]{article}

\usepackage{lipsum} % for the mock text

\usepackage{mdframed}

\begin{document}

\lipsum[1]

\begin{mdframed}[
  leftmargin=\parindent,
  rightmargin=\parindent,
  skipabove=\topsep,
  skipbelow=\topsep
  ]
  \emph{Alpha particles} (named after
    and denoted by the first letter in the Greek
alphabet) consist of two protons and two neutrons bound
together. This means
that a particle is a helium nucleus.
\end{mdframed}

\lipsum[2]

\end{document}

enter image description here

  • That's exactly what I need ! How can I get this ? – ExpertNoob Jun 9 '12 at 12:57
  • 5
    @ExpertNoob Sorry. I want to sleep at night without being obsessed by the spirits of Gutenberg, Manuzio, Tschichold and others seeking for revenge. :) – egreg Jun 9 '12 at 13:00
  • @ExpertNoob Oh, I had hoped that in spite of mentioning the hyperref box you are not exactly looking for a one-line-height box. Well, you might nevertheless consider my answer, which I think is a much more pleasant way of boxing text. – dgs Jun 9 '12 at 13:19
  • @egreg High five for edit timing and +1 for the high-level version. – dgs Jun 9 '12 at 13:25
  • @egreg: I've done my research before asking, and I'm now pretty knowledgeable about all things framed. I am specifically looking for the "line-following" box like on your first image. Can I have the source for that please ? – ExpertNoob Jun 9 '12 at 18:56
5

Here are two solutions that keep the \fbox. The text to be framed is wrapped by a \parbox to ensure line breaks, and indentation is adjusted. The first variant keeps the column line width for the text. Consequently, it will result in an overfull \hbox, which you may or may not mind. Alternatively, the width of the \parbox can be adjusted such that the \fbox exactly fits into \linewidth, which is shown in the right column.

enter image description here

Code

\documentclass[twocolumn]{article}
\raggedbottom       %don't stretch space between paragraphs to fill columns
\usepackage{lipsum}
\usepackage{calc}

\newlength\defaultparindent
\setlength{\defaultparindent}{\parindent}   %save default indentation   

\begin{document}
\section{Section}

\lipsum[75]
\vspace{\dimexpr.8pt+\fboxsep\relax}        %add interline space

%Version 1
{%group to keep \parindent change local
    \parindent-\fboxsep     %revert indentation due to \fbox frame space
    \indent%    
    \fbox{%
        \parbox{\linewidth}{%
        \parindent\defaultparindent%
        \indent Alpha particles (named after and denoted by the first letter in the Greek alphabet) consist of two protons and two neutrons bound
    together. This means that an  particle is a helium nucleus.}}
}%end parindent group

\vspace{\dimexpr.8pt+\fboxsep\relax}    

\lipsum[1]
\pagebreak
\lipsum[1]

\vspace{\dimexpr.8pt+\fboxsep\relax}

%Version 2
\noindent       
\fbox{%
    \parbox{\linewidth-2\fboxsep-1.6pt}{%
    \parindent\defaultparindent%
    \indent Alpha particles (named after and denoted by the first letter in the Greek alphabet) consist of two protons and two neutrons bound
together. This means that an  particle is a helium nucleus.}}

\vspace{\dimexpr.8pt+\fboxsep\relax}

\lipsum[75]     
  \end{document}
  • This solution has the merit of not needing any package. It's possible to avoid warnings with the first way, but I'd go with the second. – egreg Jun 9 '12 at 13:29
  • I'd choose either the first or a larger indent, as in your solution, since with no indent being the reader's reference level, a too narrow indent may be perceived as "wrong" rather than intended. – dgs Jun 9 '12 at 13:37
1
\documentclass{article}
\usepackage{soul}
\usepackage{color}
\begin{document}
This is \texthl{a very, very, very, very, in fact, an obscenely long
  and considerably friendly text}, my friend.
\end{document}

You'll find that the basic mechanism of the soul package used for text highlighting is required also for framed texts that are supposed to linewrap: the bulk of linewrapped boxes consists of an overline and an underline at fixed height. I actually have a hard time imagining this kind of construct with borders looking nice in a linewrapped context, but it sounds like this is what you are after. When the boxes do not appear in mid-line but as containers/blocks of their own, the framed package will offer a variety of styles.

  • Thanks, that can be useful. But I'm really after a frame, not background coloring. – ExpertNoob Jun 9 '12 at 12:31
0

Closest thing I could find is Ulrike's varbox (using \columnwidth instead of \linewidth + some customization for tighter boxes):

\makeatletter
\newcommand{\varbox}[1]{%
  \setlength{\@tempdima}{\dimexpr\columnwidth\relax}%
  \sbox{\@tempboxa}{#1}%
  \ifdim\wd\@tempboxa>\@tempdima
    \begingroup\fboxsep=0.6mm
      \fbox{\parbox{\@tempdima}{\strut #1}}%
    \endgroup
    \vspace{\dimexpr-2pt\relax}
  \else
    \begingroup\fboxsep=0.4mm
      \fbox{\strut #1} 
    \endgroup
  \fi}
\makeatother

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.