# problem with theorem, tikzpicture and center environment

I use a dialog-bubble style for some theorems, by using the code below, that works fine.

\documentclass[a4paper,11pt,twoside]{book}
\usepackage[a4paper,left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{amsthm}

\usepackage{environ}

\usepackage{tikz}
\usetikzlibrary{shapes,snakes} % Για φάνσι κουτακια

\theoremstyle{plain}
\newtheorem{theo}{Sometheorem}[chapter]

\tikzstyle{BoxDialog} = [draw=black, fill=white, very thick,
rectangle callout, rounded corners, densely dashed,callout relative pointer={(-0.4cm,-0.4cm)}, inner sep=4pt, inner ysep=8pt]
\tikzstyle{TitlTheo} =[fill=white, text=black]

\NewEnviron{dialogtheo}[1]{
\begin{tikzpicture}
\node [BoxDialog] (boxtheo){%
\begin{minipage}{0.9\textwidth}
\BODY
\end{minipage}
};
\node[TitlTheo] at (boxtheo.north) {\textbf{#1}};
\end{tikzpicture}
}

\begin{document}

\begin{dialogtheo}{title theorem}
\begin{theo}
theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem
\end{theo}
\end{dialogtheo}

\end{document}


But when I wrap center environment around the dialogtheo environment like this:

\NewEnviron{dialogtheo}[1]{
\begin{center}
\begin{tikzpicture}
\node [BoxDialog] (boxtheo){%
\begin{minipage}{0.9\textwidth}
\BODY
\end{minipage}
};
\node[TitlTheo] at (boxtheo.north) {\textbf{#1}};
\end{tikzpicture}
\end{center}
}


I have this error report:

! LaTeX Error: Something's wrong--perhaps a missing \item.

This is the log-file.

What is the problem?

P.S.: If I ceep center environment, but I delete theo, everything is OK again.

If your goal is to center the dialog bubble, instead of using the center environment, you should try to use \centering with a \par at the end of the content of your environment:

\NewEnviron{dialogtheo}[1]{
\centering
\begin{tikzpicture}
\node[BoxDialog] (boxtheo){
\begin{minipage}{0.9\textwidth}
\BODY
\end{minipage}
};
\node[TitlTheo] at (boxtheo.north) {\textbf{#1}};
\end{tikzpicture}\par
}


The \par is important, else the bubble will not be centered at all.

If you try to place a theorem inside center environment, you will realize that it doesn't work.

Edit: I mean that the code:

\begin{center}
\begin{theo}
test
\end{theo}
\end{center}


would result to a non-centered theorem.

So, my solution is a "hack" that just indenting your environment as much as needed:

\documentclass[a4paper,11pt,twoside]{book}
\usepackage[a4paper,left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{amsthm}
\usepackage{lipsum}
\usepackage{environ}

\usepackage{tikz}
\usetikzlibrary{shapes,decorations} % Για φάνσι κουτακια

\theoremstyle{plain}
\newtheorem{theo}{Sometheorem}[chapter]

\tikzstyle{BoxDialog} = [draw=black, fill=white, very thick,
rectangle callout, rounded corners, densely dashed,callout relative pointer={(-0.4cm,-0.4cm)}, inner sep=4pt, inner ysep=8pt]
\tikzstyle{TitlTheo} =[fill=white, text=black]

\newsavebox{\theobox}
\newlength{\theoidentlength}
\NewEnviron{dialogtheo}[1]{
\savebox\theobox{\hbox{
\begin{tikzpicture}
\node [BoxDialog] (boxtheo){%
\begin{minipage}{0.6\textwidth}
\BODY
\end{minipage}
};
\node[TitlTheo] at (boxtheo.north) {\textbf{#1}};
\end{tikzpicture}}}
\setlength\theoidentlength{\dimexpr(\textwidth-\wd\theobox)/2\relax}
\noindent\hspace*{\theoidentlength}\usebox{\theobox}
}

\begin{document}
\lipsum[1]
\begin{dialogtheo}{title theorem}

\begin{theo}
theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem
\end{theo}
\end{dialogtheo}

\end{document}


PS: My solution is just an alternative [that I think could be useful in many cases if centering fails], and just added as such (an alternative) approach.

• I don't agree with you about theorems problem with centering. If I wrap around \BODY the command \begin{center}Something\end{center}, like this: \begin{center}Something\end{center}\BODY\begin{center}Something\end{center}, then there is no problem with centering the dialog and the theorem. – Kώστας Κούδας Mar 27 at 9:39
• Γεια σου @ΚώσταςΚούδας (:Hi) : check the edit to see what I mean because possibly I didn't understood your goal or/and you didn't understood what I tried to do. – koleygr Mar 27 at 9:46
• Καλημέρα, @koleygr ! I thought that you meant that if I put a theorem in a center environment, I 'll have errors. So I understand your proposition! – Kώστας Κούδας Mar 27 at 9:49
• No, as you see, it will not give errors, but will just use all the available text width. Something like \begin{center} \begin{minipage}{0.5\textwidth} \begin{theo} test \end{theo} \end{minipage} \end{center} would center anyway... My proposal is just a more general approach that could help in similar problems. (Just adding for its idea.) Have a nice day. PS: Replace the library snakes with decorations as your compiler is suggesting. – koleygr Mar 27 at 9:53