在表格中标记方程式

在表格中标记方程式
\documentclass{article}
\usepackage{tabularx}
\usepackage{natbib}
\bibpunct{(}{)}{;}{a}{,}{,} % I added this

\usepackage{verbatim}  % for commenting

\usepackage{float}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{verbatim}  % for commenting

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{siunitx}


\newcommand{\stone}{\theta_1}

\newcommand{\sx}{x}
\newcommand{\sy}{y}

\begin{document}

\begin{table} [tbp]
\centering
  \caption{Equations}
  \label{table:Equations}
  \begin{tabular}{p{0.45in} p{0.5in} p{2.4in}} % {@{}ll@{}}
    \toprule
    \textbf{Inputs} & \textbf{Output} & \textbf{Equation} \\
    \midrule
    
   \rotatebox[origin=c]{0}{$\stone$}
    & $\sx$ & \begin{equation}\tag{1}
        0.5 \cos(2\pi\stone) + 0.5
    \end{equation}  \\%\hline

   \rotatebox[origin=c]{0}{$\stone$}
    & $\sy$ & \begin{equation}\tag{2} 0.5\sin(2\pi\stone) + 0.5 
    \end{equation}\\%\hline
    
\bottomrule
\end{tabular}
\end{table}

\end{document}

执行上述代码后表格如下所示:

在此处输入图片描述

其中,表格的列未正确对齐。我需要标记方程式。

答案1

为什么\rotatebox[origin=c]{0}{$\stone$}

您可以手动步进equation计数器。

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}

% not sure what's the purpose of these commands
\newcommand{\stone}{\theta_1}
\newcommand{\sx}{x}
\newcommand{\sy}{y}

\begin{document}

\begin{table}[htbp]
\centering

\caption{Equations}
\label{table:Equations}

\begin{tabular}{lllr}
\toprule
\textbf{Inputs} & \textbf{Output} & \textbf{Equation} \\
\midrule
$\stone$ & $\sx$ & $0.5 \cos(2\pi\stone) + 0.5$ &
  \refstepcounter{equation}\thetag{\theequation}\label{eq:first}
\\
$\stone$ & $\sy$ & $0.5\sin(2\pi\stone) + 0.5$ &
  \refstepcounter{equation}\thetag{\theequation}\label{eq:second}
\\
\bottomrule
\end{tabular}

\end{table}

\eqref{eq:first} and \eqref{eq:second}

\end{document}

在此处输入图片描述

答案2

像这样的东西是否更好,或者像 WinnieNotThePooh 的答案这样的东西可能取决于你想要的表格的紧凑程度,但如果你想要更紧凑的东西,你可以手动增加方程计数器:

\documentclass{article}
\usepackage{tabularx}
\usepackage{natbib}
\bibpunct{(}{)}{;}{a}{,}{,} % I added this

\usepackage{verbatim}  % for commenting

\usepackage{float}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{verbatim}  % for commenting

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{siunitx}

\newcommand{\stone}{\theta_1}

\newcommand{\sx}{x}
\newcommand{\sy}{y}

\begin{document}

\begin{table}[tbp]
\centering
  \caption{Equations}
  \label{table:Equations}
  \begin{tabular}{p{0.45in} p{0.5in} p{2.2in} r@{}} % {@{}ll@{}}
    \toprule
    \textbf{Inputs} & \textbf{Output} & \textbf{Equation} & \\
    \midrule
    $\stone$
    & $\sx$
    & $0.5 \cos(2\pi\stone) + 0.5$
    & \refstepcounter{equation}(\theequation)\label{eq:one}
    \\
    $ \stone$
    & $\sy$
    & $0.5\sin(2\pi\stone) + 0.5$
    & \refstepcounter{equation}(\theequation)\label{eq:two}
    \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

您仍然可以\ref按照正常方式使用 等来引用它们。

方程表

答案3

使用tabularray软件包:两种可能的解决方案

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs, counter, varwidth}


\begin{document}
\addtocounter{equation}{-1}
\begin{tblr}{colspec = {*{2}{Q[l,m, mode=math]}
                             X[c,m, mode=dmath]
                             Q[r, cmd=\refstepcounter{equation}]},
              row{1} = {font=\bfseries, c, mode=text},
             measure = vbox,
             }
    \toprule
Inputs      &   Output  &   Equation    &           \\
    \midrule
\theta_1    &   y   &   %
                        0.5 \cos(2\pi\theta_1) + 0.5  & \thetag{\theequation}\label{eq:first}   \\
\theta_1    &   y   &   %
                        0.5 \cos(2\pi\theta_1) + 0.5  & \thetag{\theequation}\label{eq:second}  \\
    \bottomrule
\end{tblr}

\medskip
\eqref{eq:first} and \eqref{eq:second}

\vspace{3ex}
\begingroup
    \setlength\abovedisplayskip{-1ex}
    \setlength\belowdisplayskip{-1ex}
\begin{tblr}{colspec = {*{2}{Q[l,m, mode=math]}
                             X[c,m]},
             row{1} = {font=\bfseries, c, mode=text},
           row{2-Y} = {rowsep=-2ex},
            measure = vbox,
             }
    \toprule
Inputs      &   Output  &   Equation        \\
    \midrule
\theta_1    &   y   &   \begin{equation}\label{eq:third}
                        0.5 \cos(2\pi\theta_1) + 0.5
                        \end{equation}      \\
\theta_1    &   y   &   \begin{equation}\label{eq:fourth}
                        0.5 \cos(2\pi\theta_1) + 0.5
                        \end{equation}      \\
\theta_1    &   y   &   \begin{equation}\label{eq:fifth}
                        0.5 \cos(2\pi\theta_1) + 0.5
                        \end{equation}      \\
    \bottomrule
\end{tblr}
\endgroup

\medskip
\eqref{eq:third}, \eqref{eq:fourth}  and \eqref{eq:fifth}
\end{document}

在此处输入图片描述

答案4

您不能\begin{equation}...\end{equation}在表格单元格内使用。如果您希望它看起来像显示的方程式,您可以这样做:

... & \(\displaystyle 0.5 \cos(2\pi\stone) + 0.5 \)  

但你可以尝试这样的方法:

\documentclass{article}
\usepackage{tabularx}
\usepackage{natbib}
\bibpunct{(}{)}{;}{a}{,}{,} % I added this

\usepackage{verbatim}  % for commenting

\usepackage{float}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{verbatim}  % for commenting

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{siunitx}


\newcommand{\stone}{\theta_1}

\newcommand{\sx}{x}
\newcommand{\sy}{y}

\begin{document}

\begin{table} [tbp]
\centering
  \caption{Equations}
  \label{table:Equations}
  \begin{tabular}{p{0.45in} p{0.5in} p{2.4in}} % {@{}ll@{}}
    \toprule
    \textbf{Inputs} & \textbf{Output} & \textbf{Equation} \\
    \midrule
    
   \rotatebox[origin=c]{0}{$\stone$}
    & $\sx$ &  \parbox{4cm}{\begin{equation} 0.5 \cos(2\pi\stone) + 0.5 \end{equation}} \\%\hline

   \rotatebox[origin=c]{0}{$\stone$}
    & $\sy$ &  \parbox{4cm}{\begin{equation} 0.5\sin(2\pi\stone) + 0.5 \end{equation}}\\%\hline
    
\bottomrule
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

因此,正如您所理解的,在表格中列举方程式并不是一个好主意,但我建议您看一下这个答案并做出类似的东西)

相关内容