多行未定义控制序列

多行未定义控制序列

我在使用时遇到了一些问题multirow。我不确定这是否是由于字体问题,qcr因为我刚刚开始学习 LaTeX。有人能帮我找出问题所在吗?我创建了一个简单的文档来重现这个问题:

\documentclass[preprint]{elsarticle}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage[english]{babel}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{epsfig}
\usepackage{alltt}
\usepackage{fixme}
\usepackage[table,xcdraw]{xcolor}
\usepackage{pstricks}
\usepackage{pst-node}
\usepackage{enumerate}
\usepackage[T1]{fontenc}
\usepackage{xr}
\usepackage{graphics}
\usepackage{listings}
\usepackage{tcolorbox}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage[ruled, lined, linesnumbered, commentsnumbered, longend]{algorithm2e}
\usepackage{algpseudocode}
\usepackage{booktabs}
\usepackage{verbatim}
\journal{Journal of Computational Science}
\bibliographystyle{elsarticle-num}
\begin{document}
\begin{frontmatter} 

% ----- Title -----
\title{Blah, blah, blah\tnoteref{t1}}

% ---------- Abstract ----------
\begin{abstract}
Blah, blah, blah
\end{abstract}
\end{frontmatter}

% ---------- Table ----------
\begin{table}[]
\scriptsize
\begin{center}
\caption{The most commonly used variables for PRNG}
\begin{tabular}{|c|l|p{4.7cm}|}
\hline
\rowcolor[HTML]{EFEFEF} 
{\color[HTML]{000000} \textbf{Based on}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} \textbf{Name}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EFEFEF}{\color[HTML]{000000} \textbf{Description}}} \\ \hline
                                 & {\fontfamily{qcr}\selectfont block.coinbase}                     & Address of the miner who mined the current block\\ \cline{2-3} 
                                 & {\fontfamily{qcr}\selectfont block.difficulty}                   & Relative measure of how difficult it was to find the block\\ \cline{2-3} 
                                 & {\fontfamily{qcr}\selectfont block.gaslimit}                     & Maximum gas consumption for transactions within the block\\ \cline{2-3} 
\multirow{-5}{*}{Block variable} & {\fontfamily{qcr}\selectfont block.number}                       & Height of current block\\ \cline{2-3} 
                                 & {\fontfamily{qcr}\selectfont block.timestamp}                    & When the block was mined\\ \hline
                                 & {\fontfamily{qcr}\selectfont block.blockhash(block.number)}      & Blockhash of the current block\\ \cline{2-3} 
                                 & {\fontfamily{qcr}\selectfont block.blockhash(block.number - 1)}  & Blockhash of the last block\\ \cline{2-3} 
\multirow{-3}{*}{Blockhash}      & {\fontfamily{qcr}\selectfont block.blockhash()}                  & Blockhash of a block that is at least 256 blocks older than the current one\\ \hline
\end{tabular}
\end{center}
\end{table}

\bibliography{references}
\end{document}

答案1

  • 您需要清理您的序言(删除所有两次加载的包,移动hyperref到最后的序言)
  • 您的表格可以大大简化:
    • 通过使用(相对较新的包)tabularray
\documentclass[preprint]{elsarticle}
\usepackage[T1]{fontenc}
\usepackage[xcdraw]{xcolor}
\usepackage{tabularray}

\begin{document}

% ---------- Table ----------
    \begin{table}[htb]
    \small
    \caption{The most commonly used variables for PRNG}
\begin{tblr}{hline{1,2,Z} = 0.8pt, hline{3-Y} = 0.2pt, vlines,
             colspec = {Q[c,m, 3.4em]
                        Q[l,m, font=\fontfamily{qcr}]
                        X[l,m]},
             colsep  = 4pt,
             row{1}  = {font=\bfseries, bg=gray!30}
             }

Based on
    &   Name    &   Description                             \\
\SetCell[r=5]{c}    Block variable
    &   block.coinbase
                &   Address of the miner who mined the
                    current block                           \\
    &   block.difficulty
                &   Relative measure of how difficult it was
                    to find the block                       \\
    &   block.gaslimit
                &   Maximum gas consumption for transactions
                    within the block                        \\
    &   block.number
                &   Height of current block                 \\
    &   block.timestamp
                &   When the block was mined                \\
%
\SetCell[r=3]{c}    Block\-hash
    &   block.blockhash(block.number)
                &   Blockhash of the current block          \\
    &   block.blockhash(block.number\,-\,1)
                &   Blockhash of the last block             \\
    &   block.blockhash()
                &   Blockhash of a block that is at least
                    256 blocks older than the current one   \\
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

  • 按用途makecell和包装:multirowtabularx
\documentclass[preprint]{elsarticle}
\usepackage[T1]{fontenc}
\usepackage[table, xcdraw]{xcolor}
\usepackage{ragged2e}                       % new
\usepackage{booktabs, 
            makecell, multirow, tabularx}   % new
\renewcommand\theadfont{\bfseries}


\begin{document}

% ---------- Table ----------
    \begin{table}[htb]
    \caption{The most commonly used variables for PRNG}
    \small
    \renewcommand\tabularxcolumn[1]{m{#1}}
    \renewcommand\arraystretch{1.1}
\begin{tabularx}{\linewidth}{|>{\centering}p{3.4em}
                             |>{\fontfamily{qcr}\selectfont}l
                             |>{\RaggedRight}X|}
    \Xhline{0.8pt}
\thead{Based\\ on}
    & \thead{Name}  & \thead{Description}                   \\
    \Xhline{0.8pt}
\multirow{10}{=}{Block variable}
    &   block.coinbase
                &   Address of the miner who mined the
                    current block                           \\
    \cline{2-3}
    &   block.difficulty
                &   Relative measure of how difficult it was
                    to find the block                       \\
    \cline{2-3}
    &   block.gaslimit
                &   Maximum gas consumption for transactions
                    within the block                        \\
    \cline{2-3}
    &   block.number
                &   Height of current block                 \\
    \cline{2-3}
    &   block.timestamp
                &   When the block was mined                \\
    \hline
%
\multirow{6}{=}{Block\-hash}
    &   block.blockhash(block.number)
                &   Blockhash of the current block          \\
    \cline{2-3}
    &   block.blockhash(block.number\,-\,1)
                &   Blockhash of the last block             \\
    \cline{2-3}
    &   block.blockhash()
                &   Blockhash of a block that is at least
                    256 blocks older than the current one   \\
    \Xhline{0.8pt}
\end{tabularx}
    \end{table}
\end{document}

在此处输入图片描述

(红线表示文本区域边框)

相关内容