I'm trying to create a theoremstyle whith a shaded background. As I already have a working preamble I'd like to change as less as possible. Previously I defined an own theoremstyle 'selfdefined' which I used for theorems and such. However as this is not shading my theorems it's not an option anymore.

Now I tried to define a new theoremstyle 'shaded' which is supposed to do this. Unfortunately it's not working the way I want it to work. Instead of using the newly defined theoremstyle it just uses some kind of default theoremstyle. I hope somebody can help me to fix this (with as few changes as possible and detailed explanations, as I'm pretty much a beginner when it comes to latex).

I'm aware that this is not really a 'minimum working' example, I hope it's still alright.

\documentclass[a4paper,12pt]{scrartcl}

\usepackage[utf8]{inputenc}                     % input encoding
\usepackage[T1]{fontenc}                        % use T1 fonts for font encoding
\usepackage{amsfonts}                           % math font
\usepackage{color}
\usepackage{dsfont}                             % math font for number spaces etc.
\usepackage{helvet}                             % sans serif font
\usepackage{inconsolata}
\usepackage{tikz}                               % for drawings.
\usepackage{latexsym}
\usepackage{stmaryrd}
\usepackage{mathtools}
\usepackage{parskip}                            % vertical space instead of indentation
\usepackage{thmtools}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}

\newtheoremstyle{selfdefined}
{12pt}% Space above
{12pt}% Space below
{}% Body font \itshape =italian style
{}% Indent amount
{\newline}% Space after theorem heading, 0.5em => in gleicher zeile weiter
{}% Theorem head spec (can be left empty, meaning ‘normal’)

\declaretheoremstyle[
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
mdframed={
skipabove=\topsep,
skipbelow=\topsep,
hidealllines=true,
innerleftmargin=0pt,
innerrightmargin=0pt}

%\swapnumbers
\newtheorem{definition}{Definition}[section]
\newtheorem{theorem}[definition]{Theorem}
\newtheorem{conjecture}[definition]{Conjecture}
\newtheorem{corollary}[definition]{Corollary}
\newtheorem{lemma}[definition]{Lemma}
\newtheorem{example}[definition]{Example}
\newtheorem*{algorithm}{Algorithm}

\begin{document}
\begin{definition}[\textbf{Definition 1}]
This is supposed to be a definition in shaded style.
\end{definition}

\begin{theorem}
This is supposed to be a theorem in shaded style.
\end{theorem}
\end{document}


There are several problems; the first two are the main ones:

• You need to load thmtools after amsthm.

• Since you used \declaretheoremstyle for the shaded style, you need to define your structures using \declaretheorem instead of \newtheorem, and pass the shaded style as an option to the style key instead of using \theoremstyle.

• Load hyperref in the last place (except some exceptions which can be found elsewhere here).

• Since you are using a KOMA class, instead of loading the parskip package you should use the parskip class option; in my example I used parskip=half+ but you can use the desired value (refer to the KOMA users guide to see available options).

\documentclass[a4paper,12pt,parskip=half+]{scrartcl}
\usepackage[utf8]{inputenc}                     % input encoding
\usepackage[T1]{fontenc}                        % use T1 fonts for font encoding
\usepackage{amsfonts}                           % math font
\usepackage{color}
\usepackage{dsfont}                             % math font for number spaces etc.
\usepackage{helvet}                             % sans serif font
\usepackage{inconsolata}
\usepackage{tikz}                               % for drawings.
\usepackage{latexsym}
\usepackage{stmaryrd}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}

\newtheoremstyle{selfdefined}
{12pt}% Space above
{12pt}% Space below
{}% Body font \itshape =italian style
{}% Indent amount
{\newline}% Space after theorem heading, 0.5em => in gleicher zeile weiter
{}% Theorem head spec (can be left empty, meaning ‘normal’)

\declaretheoremstyle[
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
spaceabove=6pt,
mdframed={
skipabove=8pt,
skipbelow=6pt,
hidealllines=true,
innerleftmargin=0pt,
innerrightmargin=0pt}

\begin{document}

\section{A test section}
\begin{definition}[\textbf{Definition 1}]
This is supposed a definition in shaded style.
\end{definition}
Some test text
\begin{theorem}
This is a theorem in shaded style.
\end{theorem}

\end{document}


The result:

The result:

• Nice, thank you very much, thats exactly what I was looking for. Unfortunately a new problem just arose. Oftentimes the boxes don't really use up the space. So before a pagebreak, theres a space of up to 5-6 lines which is not used by the box, even though the 'insides' would neatly fit in there. Is there a way to fix this? – sblasher Aug 5 '15 at 21:43
• @sblasher You're welcome. Since some code is needed for tests, I think this new problem deserves a new question; the best course of action now would be to open a follow-up question providing a MWE allowing us to reproduce the problem. – Gonzalo Medina Aug 5 '15 at 22:19