1

I would like to have a style for theorems identical to lstlisting with frame=lines but I could not find a option for declaretheorem to do so. Going away from thmtools is not easy as I have already plenty of other theorems (in different styles).

\documentclass{article}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{listings}

\declaretheorem[style=definition,numbered=no,shaded={rulecolor=Black,rulewidth=0.5pt,margin=0.5em,bgcolor={rgb}{1,1,1}}]{theorem}
\lstset{frame=lines}

\begin{document}
\begin{lstlisting}
Test
\end{lstlisting}
\begin{theorem}
\end{theorem}
\end{document}

Yields: problem

I would like to have the "Theorem." in the same box as "Test" and still use declaretheorem (as I need it for many different styles).

Thank you!

1

This is very easy to obtain with ntheorem (which cooperates with thmtools, but isn't required here):

\documentclass{article}
\usepackage[dvipsnames,table]{xcolor}
\usepackage[showframe]{geometry}
\usepackage{mathtools}
\usepackage[thmmarks, amsmath]{ntheorem}
\usepackage{thmtools}
\usepackage{listings}
\lstset{frame=lines}%

\theoremstyle{nonumberplain}
\theoremprework{\bigskip\hrule}
\theorempostwork{\vspace*{-0.35ex}\hrule}
\theoremindent=0.5em
\theoremrightindent=0.5em
\theoremheaderfont{\upshape\bfseries}
\theoremseparator{.}
\theorembodyfont{\upshape}
\newtheorem{theorem}{Theorem}

\begin{document}

\vspace*{1cm}
\begin{lstlisting}
Test. Test. Test. Test. Test. Test.
\end{lstlisting}

\begin{theorem}
  Blah blah. Blah blah. Blah blah. Blah blah. Blah blah. Blah blah. Blah blah. Blah blah.
\end{theorem}

\end{document} 

enter image description here

  • Thank you, it is a beautiful solution but it seems like I have a package conflict with amsthm vs. ntheorem. (Errors are " LaTeX Error: Command \theoremstyle already defined." or "Package ntheorem Error: Theorem style plain already defined.", depending on the order) – markus23 Jul 29 '17 at 7:42
  • That's right. You have to choose between amsthm and ntheorem. Note the latter has an amsthm option, which predefines the same layout as amsthm. Also, one superiority of ntheorem is its automatic placement of the end-of-proof symbol (even when the proof in question ends up with a mulitline equation). – Bernard Jul 29 '17 at 10:16
  • Thank you, switching to ntheorem helped (with the initial problem asked here) and it was quickly done (even though I have nearly a dozen of theoremstyles: the conversion is really straight forward). – markus23 Sep 6 '17 at 20:22

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.