6

I wanted to frame in a box a text which includes tabbing. Both \framebox and tabbing works fine separately but cannot make them work together.

\framebox{
\begin{tabbing} 
\textit{Input:} \hspace*{13mm} \= assd \\
\textit{Problem:} \> adas  \\
\end{tabbing}
}
1
  • Not sure whether this is an alternative to your usage, but using you can use some \phantoms achieve the appropriate alignment.
    – Werner
    Sep 4, 2013 at 0:45

3 Answers 3

3

You can box the tabbing before framing it; in the following example I show two possibilities; the firs one, using a \vbox and the second one using a varwidth environment from the varwidth package:

\documentclass{article}
\usepackage{varwidth}

\begin{document}

\framebox{%
\vbox{\begin{tabbing} 
\textit{Input:} \hspace*{13mm} \= assd \\
\textit{Problem:} \> adas
\end{tabbing}}%
}

\framebox{\begin{varwidth}{\linewidth}
\begin{tabbing} 
\textit{Input:} \hspace*{13mm} \= assd \\
\textit{Problem:} \> adas
\end{tabbing}
\end{varwidth}}

\end{document}

enter image description here

You seem to be typesetting algorithms; in this case, some dedicated packages such as algorithmicx or listings could be useful for you.

0
2

A \framebox expects only material that doesn't split across lines; so we need to box the tabbing; if a minipage contains only a tabbing environment, it will adapt its width to that of the tabbing (if smaller than the stated width).

You are probably better served from a new environment:

\documentclass{article}

\newsavebox{\ftabbingbox}
\newenvironment{ftabbing}
  {\begin{lrbox}{\ftabbingbox}
   \begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}
   \begin{tabbing}}
  {\end{tabbing}
   \end{minipage}
   \end{lrbox}
   \fbox{\usebox{\ftabbingbox}}}

\begin{document}

\begin{ftabbing}
\textit{Input:} \hspace*{13mm} \= assd \\
\textit{Problem:} \> adas
\end{ftabbing}

\end{document}

enter image description here

2

Here's an alternative:

enter image description here

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\begin{document}
\begin{tabular}{|>{\itshape}l@{}l|}
  \hline
  Input: \hspace*{13mm} & assd \\
  Problem:              & adas \\
  \hline
\end{tabular}
\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.