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?

N.N.
  • 36,163
N3buchadnezzar
  • 11,348
  • 7
  • 55
  • 114

2 Answers2

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!

Seamus
  • 73,242
  • I expect this could be partially automated with a wrapper for \item but I don't have time to experiment right now… – Seamus Nov 02 '11 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

Gonzalo Medina
  • 505,128