我正在尝试命名一个真值表,它是使用“displaymath”和“array”命令创建的。我想知道如何将其命名为“表 1:等...”我尝试使用 caption 命令,但出现错误“caption outside of float”
这是代码
\documentclass[12pt]{report}
\usepackage[a4paper]{geometry}
\usepackage[myheadings]{fullpage}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx, wrapfig, subcaption, setspace, booktabs}
\usepackage[T1]{fontenc}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage{fourier}
\usepackage[protrusion=true, expansion=true]{microtype}
\usepackage[english, spanish]{babel}
\usepackage{sectsty}
\usepackage{url, lipsum}
\usepackage[utf8]{inputenc}
\usepackage[export]{adjustbox}
\usepackage{float}
\usepackage[nodayofweek,level]{datetime}
\usepackage{caption}
\newcommand{\mydate}{\formatdate{31}{8}{2017}}
\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\onehalfspacing
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}
\pagestyle{fancy}
\fancyhf{}
\setlength\headheight{15pt}
\fancyhead[L]{Carné: B31791}
\fancyhead[R]{Universidad de Costa Rica}
\fancyfoot[R]{Página \thepage\ de \pageref{LastPage}}
\begin{document}
\title{ \normalsize \textsc{Circuitos Digitales 1}
\\ [2.0cm]
\HRule{0.5pt} \\
\LARGE \textbf{\uppercase{Tarea 1}}
\HRule{2pt} \\ [0.5cm]
\normalsize \selectlanguage{spanish} \mydate \vspace*{5\baselineskip}}
\date{}
\author{
Carné: B31791 \\
Universidad de Costa Rica \\
Escuela de Ingeniería Eléctrica }
\maketitle
\newpage
\sectionfont{\scshape}
\section*{Tablas de verdad}
Se realizaron varias tablas de verdad para apreciar de manera concisa lo realizado en cada etapa del proceso. La primera tabla de verdad muestra cómo se realiza la suma de los \textit{LSB} de los números A y B junto con el ${{\rm{C}}_{{\rm{in}}}}$ (carry in) . Se utiliza la conectiva \textit{XOR} para la suma:
\begin{displaymath}
\begin{array}{|c c|c c|}
% |c c|c| means that there are three columns in the table and
% a vertical bar ’|’ will be printed on the left and right borders,
% and between the second and the third columns.
% The letter ’c’ means the value will be centered within the column,
% letter ’l’, left-aligned, and ’r’, right-aligned.
{{\rm{A}}_{\rm{0}}} & {{\rm{B}}_{\rm{0}}} & {{\rm{S}}_0} & {{\rm{C}}_{{\rm{in}}}}\\ % Use & to separate the columns
\hline % Put a horizontal line between the table header and the rest.
0 & 0 & 0 & 0\\
0 & 1 & 1 & 0\\
1 & 0 & 1 & 0\\
1 & 1 & 0 & 1\\
\captionof{table}{Suma de los \textit{LSB}}
\end{array}
\end{displaymath}
La siguiente tabla de verdad contiene la suma de los \textit{MSB} de los números a sumar, el
\end{document}
答案1
- 不使用浮点数的解决方案
table
:
\documentclass[12pt]{report}
\usepackage[a4paper]{geometry}
\usepackage{caption}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{center}
\captionof{table}{My important table}
\label{tab:array}
$
\begin{array}{|c c|c c|}
\mathrm{A}_{\mathrm{0}} & \mathrm{B}_{\rm{0}} & \mathrm{S}_0 & \mathrm{C}_{\mathrm{in}} \\
\hline % Put a horizontal line between the table header and the rest.
0 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 \\
1 & 0 & 1 & 0 \\
1 & 1 & 0 & 1 \\
\end{array}
$
\end{center}
\lipsum[2]
\end{document}
- 使用浮点数的解决方案
table
:
\documentclass[12pt]{report}
\usepackage[a4paper]{geometry}
\usepackage{caption}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{table}[ht]
\centering
\caption{My important table}
\label{tab:array}
\[
\begin{array}{|c c|c c|}
\mathrm{A}_{\mathrm{0}} & \mathrm{B}_{\rm{0}} & \mathrm{S}_0 & \mathrm{C}_{\mathrm{in}} \\
\hline % Put a horizontal line between the table header and the rest.
0 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 \\
1 & 0 & 1 & 0 \\
1 & 1 & 0 & 1 \\
\end{array}
\]
\end{table}
\lipsum[2]
\end{document}