矩阵整行去斜体

矩阵整行去斜体

我有一个类似矩阵:

\documentclass{article} 
\usepackage{amsmath}
\setcounter{MaxMatrixCols}{15}
\begin{document}
$\begin{bmatrix}
I & L & i & k & e & t & h & e & H & P & P & R & I & M & E \\
8 & 11 & 8 & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4
\end{bmatrix}$
\end{document}

我想使用命令取消第一行的斜体显示,但又不想让第一行变得杂乱\text{}。我该怎么做?谢谢!

答案1

这很简单tabularray

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath} 

\begin{document}
It is quite simple with \texttt{+bmatrix} adding \texttt{mode=text} option for the first row:
\[\begin{+bmatrix}[row{1}={mode=text}]
I & L & i & k & e & t & h & e & H & P & P & R & I & M & E \\
8 & 11 & 8 & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4
\end{+bmatrix}\]
The following example is just to show that the other rows are in math mode:
\[\begin{+bmatrix}[row{1}={mode=text}]
I & L & i & k & e & t & h & e & H & P & P & R & I & M & E \\
\alpha & \beta & \gamma & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4\\
a^2 & \sqrt{b} & \frac{c}{d} & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4
\end{+bmatrix}\]

Note that in the examples above the space between rows is a little larger than in an ordinary \texttt{bmatrix}. 
If you don't like it, you can set \texttt{rowsep=0pt} to have the same row separator as an ordinary \texttt{bmatrix}:
\[\begin{+bmatrix}[row{1}={mode=text}, rowsep=0pt]
I & L & i & k & e & t & h & e & H & P & P & R & I & M & E \\
8 & 11 & 8 & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4
\end{+bmatrix}\]
The following example is just to show that the other rows are in math mode:
\[\begin{+bmatrix}[row{1}={mode=text}, rowsep=0pt]
I & L & i & k & e & t & h & e & H & P & P & R & I & M & E \\
\alpha & \beta & \gamma & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4\\
a^2 & \sqrt{b} & \frac{c}{d} & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4
\end{+bmatrix}\]

The following examples are with an ordinary \texttt{bmatrix}, just to compare with the previous ones:\setcounter{MaxMatrixCols}{15}
\[\begin{bmatrix}
I & L & i & k & e & t & h & e & H & P & P & R & I & M & E \\
8 & 11 & 8 & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4
\end{bmatrix}\]
The following example is just to show that all the rows are in math mode with an ordinary \texttt{bmatrix}:
\[\begin{bmatrix}
I & L & i & k & e & t & h & e & H & P & P & R & I & M & E \\
\alpha & \beta & \gamma & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4\\
a^2 & \sqrt{b} & \frac{c}{d} & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4
\end{bmatrix}\]
\end{document}

在此处输入图片描述

答案2

(稍微简化了答案)

您可以通过以下方式实现格式化目标:(a)使用固定宽度的列类型而不是环境c所基于的列类型bmatrix;(b)将第一行封装在环境中tabular,将第二行封装在array环境中,对两者使用相同的固定宽度列类型。

请注意,由于所有单元格都具有相同的固定宽度(最常见的情况是两位数的宽度),因此整体bmatrix比以前要宽一些。请注意,我还将 等同\tabcolsep\arraycolsep,以便两种环境下的列间空白量相同。

在此处输入图片描述

\documentclass{article} 
\usepackage{amsmath} % for 'bmatrix' env. and 'MaxMatrixCols' counter
\setcounter{MaxMatrixCols}{15} % just for this example

\usepackage{array} % for '\newcolumntype' macro
\usepackage{calc}  % for '\widthof' macro
\newcolumntype{U}{wc{\widthof{19}}} % fixed-width column type
\setlength\tabcolsep\arraycolsep % 5pt instead of '6pt'

\newcommand\RowA{I & L & i & k & e & t & h & e & H & P & P & R & I & M & E}
\newcommand\RowB{8 & 11 & 8 & 10 & 4 & 19 & 7 & 4 & 7 & 15 & 15 & 17 & 8 & 12 & 4}

\begin{document}

%% "before"
$\begin{bmatrix}
  \RowA \\
  \RowB
\end{bmatrix}$

\smallskip

%% "after"
$\begin{bmatrix}
\begin{tabular}{@{} *{15}{U} @{}}
  \RowA 
\end{tabular} \\
\begin{array}{@{} *{15}{U} @{}}
  \RowB
\end{array}
\end{bmatrix}$

\end{document}

答案3

你可以这样写:

$\mathrm{
    \begin{bmatrix}
    \end{bmatrix}
 }$

假设你的矩阵中没有任何非斜体。


笔记:这实际上不起作用,因为矩阵中各个单元格的数学实际上是数学内部框内的数学,因此数学字体将被重置。我知道这一点,但一时忘了。

相关内容