3

I'm using \documentclass{book}. I would like to create theorem styles as shown in the picture below but WITHOUT \tcolorbox. For some reason \tcolorbox doesn't work for me. Any ideas? Thanks in advance!! Here is an MWE which I use currently but doesn't look like I want I want perfectly.

\documentclass{book}
\usepackage[table]{xcolor}
\usepackage{tabularx,booktabs}
\usepackage{blindtext}    
\definecolor{myblue}{RGB}{32,92,195}
\newenvironment{mybox}[1]
  {\par\medskip\noindent\arrayrulewidth=2pt\arrayrulecolor{myblue}%
   \hfill\tabularx{0.8\linewidth}{!{\color{myblue}\vrule width 2pt} X @{}}
   \multicolumn{1}{@{}l}{\tabular{@{}l}\kern\tabcolsep\textbf{#1}\\\hline\endtabular}\\}
  {\endtabularx\par\medskip}

\begin{document}

\begin{mybox}{The title with some more text in the title}
Onyl some text here
\end{mybox}

\blindtext

\begin{mybox}{The title}
\blindtext
\end{mybox}

\blindtext

\end{document}

enter image description here

  • Please add a full minimal working example so that people can see what packages etc you need to get your code to work (but don't add code that is not needed). This makes it much easier for people to help you. – Andrew Aug 5 '14 at 12:44
  • @Andrew: I just did :-) – LatexQuest Aug 5 '14 at 12:50
5
\documentclass{book}
\usepackage[table]{xcolor}
\usepackage{tabularx,booktabs}
\usepackage{blindtext}
\def\myindent{1.5ex}
\def\rulethk{1.0pt}
\definecolor{myblue}{RGB}{32,92,195}
\newenvironment{mybox}[1]
  {\par\medskip\noindent\arrayrulewidth=2pt\arrayrulecolor{myblue}%
   \tabularx{\linewidth}{!{\color{myblue}\hspace{\myindent}\vrule width \rulethk} X @{}}
   \multicolumn{1}{@{}l}{\tabular{@{}l@{}}\textbf{#1}\\\hline\endtabular}\\}
  {\\\color{myblue}\hspace{\myindent}\smash{\rule[.5pt]{10ex}{\rulethk}}\endtabularx\par\smallskip}

\begin{document}

\begin{mybox}{The title with some more text in the title}
Only some text here
\end{mybox}

\blindtext

\begin{mybox}{The title}
\blindtext
\end{mybox}

\blindtext

\end{document}

enter image description here

  • Excellent! Thanks a lot, exactly what I wanted! – LatexQuest Aug 5 '14 at 13:28
  • @LatexQuest You are welcome. Most of the changes were just playing around with the tabular @ parameters, an \hspace here or there, and rule thickness. The trailing horizontal line was new, being added in the close-out of the environment. – Steven B. Segletes Aug 5 '14 at 13:30
  • @LatexQuest FYI, I made small tweaks to the solution, in reference to space above and below trailing blue line. – Steven B. Segletes Aug 5 '14 at 13:42
  • Thanks! Which parameters do I have to play around with to be able to adjust them? – LatexQuest Aug 5 '14 at 14:09
  • @LatexQuest The [.5pt] optional argument to \rule moved the rule up slightly to avoid a gap forming. If you wanted to significantly lower the rule, you would have to add a leading vertical rule to pick up where the left-rule leaves off. As far as after the rule, I changed the \medskip to a \smallskip to better match your illustration. – Steven B. Segletes Aug 5 '14 at 17:30
2

You could also use the 'thmbox' package, a package defining a theorem environment. This makes the same "boxes" around the theorems as you'd like to have. If you'll have a look here, you'll get an extra option to change the color of the surrounding box.

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.