我目前正在使用编写文档thm工具,我想包括tikz图片以定理环境为中心。
当我在 tikzpicture 之前有一些文本时,它运行良好,但是如果我在定理中包含的唯一内容是居中的 tikzpicture,那么定理的标题就会随图片移动。
如何在不添加前面的文字的情况下防止标题随图片移动?
下面提供了一个工作示例:
\documentclass{report}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{tikz}
\usepackage{framed}
\usepackage{xcolor}
\renewenvironment{leftbar}{%
\def\FrameCommand{{\vrule width 3pt} \hspace{10pt}}%
\MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\endMakeFramed}
\declaretheoremstyle[
headformat=\color{blue}\NAME~\NUMBER~ -- \NOTE\newline,
headpunct={},
preheadhook=\begin{leftbar},
postfoothook=\end{leftbar},
]{base}
\declaretheorem[style=base]{theorem}
\begin{document}
\begin{theorem}[Title stays]
Some text.
\end{theorem}
\begin{theorem}[Title still stays]
Some text.
\begin{center}
\begin{tikzpicture}
\draw[gray, thick] (-1,2) -- (2,-4);
\draw[gray, thick] (-1,-1) -- (2,2);
\filldraw[black] (0,0) circle (2pt) node[anchor=west] {Intersection point};
\end{tikzpicture}
\end{center}
\end{theorem}
\begin{theorem}[Title moves]
\begin{center}
\begin{tikzpicture}
\draw[gray, thick] (-1,2) -- (2,-4);
\draw[gray, thick] (-1,-1) -- (2,2);
\filldraw[black] (0,0) circle (2pt) node[anchor=west] {Intersection point};
\end{tikzpicture}
\end{center}
\end{theorem}
\end{document}
答案1
这是一个解决方法,但为什么不在\hfill
后面放一个begin{theorem}[Title moves]
呢?对我来说,它有效。
\begin{theorem}[Title moves]
\hfill
\begin{center}
\begin{tikzpicture}
\draw[gray, thick] (-1,2) -- (2,-4);
\draw[gray, thick] (-1,-1) -- (2,2);
\filldraw[black] (0,0) circle (2pt) node[anchor=west] {Intersection point};
\end{tikzpicture}
\end{center}
\end{theorem}
[@Emil Njor 评论后更新的答案]
删除标题和图形之间的空格的另一种解决方法是:在环境vspace{-\baselineskip}
中添加center
。虽然不是很干净,但至少可以完成工作。
\begin{theorem}[Title moves]
\hfill
\begin{center}
\vspace{-\baselineskip}
\begin{tikzpicture}
\draw[gray, thick] (-1,2) -- (2,-4);
\draw[gray, thick] (-1,-1) -- (2,2);
\filldraw[black] (0,0) circle (2pt) node[anchor=west] {Intersection point};
\end{tikzpicture}
\end{center}
\end{theorem}