如何将带有标题的表格放入“mdframed”定理示例样式框中

如何将带有标题的表格放入“mdframed”定理示例样式框中

我有一本书,想在“mdframed”定理示例样式框内放置一个带标题的表格。没有开始/结束表格和标题,我可以做到。但有标题就不行。以下是我的代码:

\documentclass[openany]{book}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{changepage}
\usepackage{geometry}
\geometry{paperheight=9.8125in,paperwidth=8in, left=.5in, 
right=.5in,top=.75in,bottom=.4375in }
\renewcommand{\rmdefault}{pag}
\usepackage{mdframed}
\mdfdefinestyle{exampledefault}{linewidth=2pt}
\usepackage{amsthm}
\newtheorem{my_example}{EXAMPLE}[chapter]
\begin{document}
\begin{adjustwidth}{2.25in}{0pt}
\chapter{first chapter}
\section{first section}
This is my first table:
\begin{table}[h!]
\begin{adjustwidth}{2.25in}{0pt}
\begin{center}
\begin{tabular}{|c|c|c|}
\hline $x$ &  $y$   &  $z$ \\
\hline $a$&$b$ &$c$ \\
\hline
\end{tabular}
{\caption{my first table}} \label{table_first}
\end{center}
\end{adjustwidth}
\end{table}

Now I have this text box:
\begin{mdframed}[style=exampledefault]
\begin{my_example}\label{example_first}
I want to have another table here:

 \begin{center}
 \begin{tabular}{|c|c|c|}
 \hline $a$ &  $b$   &  $c$ \\
 \hline $x$&$y$ &$z$ \\
 \hline
 \end{tabular}
 \end{center}


\end{my_example}
\end{mdframed}

\end{adjustwidth}
 \end{document}

答案1

H我认为这是该包中此处的完美用例(因为如果需要的话,float它可以更容易地再次改回浮点数(比使用构造)):captureof

\documentclass[openany]{book}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{changepage}
\usepackage{geometry}
\usepackage{caption}
\usepackage{float}
\geometry{paperheight=9.8125in,paperwidth=8in, left=.5in, 
right=.5in,top=.75in,bottom=.4375in }
\renewcommand{\rmdefault}{pag}
\usepackage{mdframed}
\mdfdefinestyle{exampledefault}{linewidth=2pt}
\usepackage{amsthm}
\newtheorem{my_example}{EXAMPLE}[chapter]
\begin{document}
\begin{adjustwidth}{2.25in}{0pt}
\chapter{first chapter}
\section{first section}
This is my first table:
\begin{table}[h!]
\begin{adjustwidth}{2.25in}{0pt}
\begin{center}
\begin{tabular}{|c|c|c|}
\hline $x$ &  $y$   &  $z$ \\
\hline $a$&$b$ &$c$ \\
\hline
\end{tabular}
{\caption{my first table}} \label{table_first}
\end{center}
\end{adjustwidth}
\end{table}

Now I have this text box:
\begin{mdframed}[style=exampledefault]
\begin{my_example}\label{example_first}
I want to have another table here:

 \begin{table}[H]
 \begin{center}
 \begin{tabular}{|c|c|c|}
 \hline $a$ &  $b$   &  $c$ \\
 \hline $x$&$y$ &$z$ \\
 \hline
 \end{tabular}
 {\caption{my second table}} \label{table_second}
 \end{center}
 \end{table}


\end{my_example}
\end{mdframed}

\end{adjustwidth}
 \end{document}

在此处输入图片描述 但我想有些人对此强烈反对……为什么浮点数中不应该使用“H”选项?

答案2

以下是使用该\captionof命令的替代方法:

在此处输入图片描述

\documentclass[openany]{book}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{changepage}
\usepackage{geometry}
\geometry{paperheight=9.8125in,paperwidth=8in, left=.5in, 
right=.5in,top=.75in,bottom=.4375in }
\renewcommand{\rmdefault}{pag}
\usepackage{mdframed}
\mdfdefinestyle{exampledefault}{linewidth=2pt}
\usepackage{amsthm}
\newtheorem{my_example}{EXAMPLE}[chapter]
\begin{document}
\begin{adjustwidth}{2.25in}{0pt}
\chapter{first chapter}
\section{first section}
This is my first table:
\begin{table}[h!]
\begin{adjustwidth}{2.25in}{0pt}
\centering
\begin{tabular}{|c|c|c|}
\hline $x$ &  $y$   &  $z$ \\
\hline $a$&$b$ &$c$ \\
\hline
\end{tabular}
\caption{my first table} \label{table_first}
\end{adjustwidth}
\end{table}

Now I have this text box:
\begin{mdframed}[style=exampledefault]
\begin{my_example}\label{example_first}
I want to have another table here:

 \begin{center}
 \begin{tabular}{|c|c|c|}
 \hline $a$ &  $b$   &  $c$ \\
 \hline $x$&$y$ &$z$ \\
 \hline
 \end{tabular}
 \end{center}
 \captionof{table}{another caption}


\end{my_example}
\end{mdframed}

\end{adjustwidth}
 \end{document}

相关内容