Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
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/… –  vertoe Jun 9 '12 at 10:39
    
@egreg: thanks. I mean \mbox for example –  ExpertNoob Jun 9 '12 at 10:40
1  
\mbox is indivisible by design. –  egreg Jun 9 '12 at 10:45
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

4 Answers 4

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

share|improve this answer
    
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

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}
share|improve this answer
    
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
    
@HarishKumar Thanks for the edit. –  dgs Jun 10 '12 at 14:37
\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.

share|improve this answer
    
Thanks, that can be useful. But I'm really after a frame, not background coloring. –  ExpertNoob Jun 9 '12 at 12:31

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.