15

Is there any way in latex to create a simple box around one item in a list? I tried both \framebox, and \fbox, none of them worked

\begin{enumerate}[label=\Alph*),ref=\Alph*]
{\color{red}\item null.} 
\item lik vektdifferansen $GT - GK$.
\item lik vektsummen $GT + GK$.
\item lik vekten av $K$.
\end{enumerate}

Works, but

\begin{enumerate}[label=\Alph*),ref=\Alph*]

{\color{red}  \fbox{ \item null.} } 

\item lik vektdifferansen $GT - GK$.
\item lik vektsummen $GT + GK$.
\item lik vekten av $K$.
\end{enumerate}

Does not. So yeah, any way to box a single entry in a list?

1
  • Presumably \item\fbox{null.} is not acceptable?
    – Seamus
    Nov 2, 2011 at 12:54

2 Answers 2

15

Here's a way of boxing the text and label. It depends on explicitly calling the label. It might also need some tweaking for spacing.

It relies on Andrew Stacey's super smart \tikzmark trick.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\begin{document}
\begin{itemize}
\item[\tikzmark{bl}\textbullet] Something\tikzmark{br}
\item Something not boxed
\item Also not boxed.
\end{itemize}
\tikz[overlay,remember picture]{\draw[red]
  ($(bl)+(-0.2em,0.9em)$) rectangle
  ($(br)+(0.2em,-0.3em)$);}
\end{document}

boxing items

I am fully aware that this is overkill. But that is a good thing!

1
  • I expect this could be partially automated with a wrapper for \item but I don't have time to experiment right now…
    – Seamus
    Nov 2, 2011 at 14:34
7

You can locally redefine \labelenumi:

\documentclass{article}
\usepackage{xcolor}

\begin{document}

\begin{enumerate}
  \item First item.
  {\renewcommand\labelenumi{\fbox{\theenumi}}
  \item Second boxed item.}
  \item Third item.
\end{enumerate}

\begin{enumerate}
  \item First item.
  {\renewcommand\labelenumi{\colorbox{red}{\theenumi}}
  \item Second boxed and colored item.}
  \item Third item.
\end{enumerate}

\end{document}

enter image description here

2
  • This only boxes the label though, not the item. Nov 2, 2011 at 12:58
  • @wh1t3 yes. I thought that that was the intention of the OP. Nov 2, 2011 at 13:04

You must log in to answer this question.

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