Text FormattingBoxed Theorem Head

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
rcamino
Posts: 2
Joined: Sun Sep 08, 2013 6:16 pm

Boxed Theorem Head

Post by rcamino »

I want to enclose the word "Theorem" with a box in an environment that I created by the \newtheorem command. Of course, with the counter. I do not want that the contents of the theorem are inside the box. I tried with \newtheorem{theo}{\fbox{Theorem}} but the box only encloses the word "Theorem" and not the counter. Also, I would like that the box is rounded.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Boxed Theorem Head

Post by gmedina »

Two possibilities. The first one, using \ovalbox from fancybox:

Code: Select all

\documentclass{article}
\usepackage{amsthm}
\usepackage{fancybox}

\makeatletter
\newtheoremstyle{caja}
  {\topsep}
  {\topsep}
  {\itshape}
  {}
  {\bfseries}
  {}
  {.5em}
  {\ovalbox{\thmname{#1}~\thmnumber{#2}\@ifempty{#3}{.}{}\thmnote{ (#3).}}}
\makeatother
\theoremstyle{caja}
\newtheorem{theo}{Theorem}

\begin{document}

\begin{theo}
test
\end{theo}

\begin{theo}[Important result]
test
\end{theo}

\end{document}
The second one, with TikZ:

Code: Select all

\documentclass{article}
\usepackage{amsthm}
\usepackage{tikz}

\makeatletter
\newtheoremstyle{caja}
  {\topsep}
  {\topsep}
  {\itshape}
  {}
  {\bfseries}
  {}
  {.5em}
  {\tikz[baseline=-.65ex]\node[draw,rounded corners] {\thmname{#1}~\thmnumber{#2}\@ifempty{#3}{.}{}\thmnote{ (#3).}};}
\makeatother
\theoremstyle{caja}
\newtheorem{theo}{Theorem}

\begin{document}

\begin{theo}
test
\end{theo}

\begin{theo}[Important result]
test
\end{theo}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
rcamino
Posts: 2
Joined: Sun Sep 08, 2013 6:16 pm

Re: Boxed Theorem Head

Post by rcamino »

Thanks, gmedina, it works! I will take the second choice since the theorems only have counters, no names.
Post Reply