我正在写一份包含大量矩阵的报告。在本文的某个地方,我写了以下代码
编辑:正如我所说,我将上传一个更好地代表我所遇到的问题的代码,包括结构配置。
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[a4paper, 11pt]{article}
\usepackage{cite} % bibtex
\input{structure}
%----------------------------------------------------------------------------------------
% ASSIGNMENT INFORMATION
%----------------------------------------------------------------------------------------
\title{Problem with matrix alignment}
\author{Not Sure \\ \texttt{[email protected]} \\ Number: \texttt{123456} }
\date{25th-Sep-2018}
\begin{document}
\maketitle
Equation (\ref{eqn:volt_hf_theta_esteemed}) is not aligned.
\begin{equation} \label{eqn:volt_hf_theta_esteemed}
\begin{bmatrix}
u_{dh}^{\hat{r}} \\
u_{qh}^{\hat{r}}
\end{bmatrix}
=
\begin{bmatrix}
j\omega_h \left(L_{avg} + \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right) & j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) \\
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) & j\omega_h \left(L_{avg} - \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right)
\end{bmatrix}
\begin{bmatrix}
i_{dsh}^{\hat{r}} \\
i_{qsh}^{\hat{r}}
\end{bmatrix}
\end{equation} % fix horiziontal alignment
\end{document}
“\input{structure}” 的内容是以下模板
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lachaise Assignment
% Structure Specification File
% Version 1.0 (26/6/2018)
%
% This template originates from:
% http://www.LaTeXTemplates.com
%
% Authors:
% Marion Lachaise & François Févotte
% Vel ([email protected])
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\usepackage{amsmath,amsfonts,stmaryrd,amssymb,tabstackengine} % Math packages
\usepackage{enumerate} % Custom item numbers for enumerations
\usepackage[ruled]{algorithm2e} % Algorithms
\usepackage[framemethod=tikz]{mdframed} % Allows defining custom boxed/framed environments
\usepackage{listings} % File listings, with syntax highlighting
\lstset{
basicstyle=\ttfamily, % Typeset listings in monospace font
}
%----------------------------------------------------------------------------------------
% DOCUMENT MARGINS
%----------------------------------------------------------------------------------------
\usepackage{geometry} % Required for adjusting page dimensions and margins
\geometry{
paper=a4paper, % Paper size, change to letterpaper for US letter size
top=2.5cm, % Top margin
bottom=3cm, % Bottom margin
left=2.5cm, % Left margin
right=2.5cm, % Right margin
headheight=14pt, % Header height
footskip=1.5cm, % Space from the bottom margin to the baseline of the footer
headsep=1.2cm, % Space from the top margin to the baseline of the header
%showframe, % Uncomment to show how the type block is set on the page
}
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage{XCharter} % Use the XCharter fonts
%----------------------------------------------------------------------------------------
% COMMAND LINE ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{commandline}
% \begin{verbatim}
% $ ls
%
% Applications Desktop ...
% \end{verbatim}
% \end{commandline}
\mdfdefinestyle{commandline}{
leftmargin=10pt,
rightmargin=10pt,
innerleftmargin=15pt,
middlelinecolor=black!50!white,
middlelinewidth=2pt,
frametitlerule=false,
backgroundcolor=black!5!white,
frametitle={Command Line},
frametitlefont={\normalfont\sffamily\color{white}\hspace{-1em}},
frametitlebackgroundcolor=black!50!white,
nobreak,
}
% Define a custom environment for command-line snapshots
\newenvironment{commandline}{
\medskip
\begin{mdframed}[style=commandline]
}{
\end{mdframed}
\medskip
}
%----------------------------------------------------------------------------------------
% FILE CONTENTS ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{file}[optional filename, defaults to "File"]
% File contents, for example, with a listings environment
% \end{file}
\mdfdefinestyle{file}{
innertopmargin=1.6\baselineskip,
innerbottommargin=0.8\baselineskip,
topline=false, bottomline=false,
leftline=false, rightline=false,
leftmargin=2cm,
rightmargin=2cm,
singleextra={%
\draw[fill=black!10!white](P)++(0,-1.2em)rectangle(P-|O);
\node[anchor=north west]
at(P-|O){\ttfamily\mdfilename};
%
\def\l{3em}
\draw(O-|P)++(-\l,0)--++(\l,\l)--(P)--(P-|O)--(O)--cycle;
\draw(O-|P)++(-\l,0)--++(0,\l)--++(\l,0);
},
nobreak,
}
% Define a custom environment for file contents
\newenvironment{file}[1][File]{ % Set the default filename to "File"
\medskip
\newcommand{\mdfilename}{#1}
\begin{mdframed}[style=file]
}{
\end{mdframed}
\medskip
}
%----------------------------------------------------------------------------------------
% NUMBERED QUESTIONS ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{question}[optional title]
% Question contents
% \end{question}
\mdfdefinestyle{question}{
innertopmargin=1.2\baselineskip,
innerbottommargin=0.8\baselineskip,
roundcorner=5pt,
nobreak,
singleextra={%
\draw(P-|O)node[xshift=1em,anchor=west,fill=white,draw,rounded corners=5pt]{%
Question \theQuestion\questionTitle};
},
}
\newcounter{Question} % Stores the current question number that gets iterated with each new question
% Define a custom environment for numbered questions
\newenvironment{question}[1][\unskip]{
\bigskip
\stepcounter{Question}
\newcommand{\questionTitle}{~#1}
\begin{mdframed}[style=question]
}{
\end{mdframed}
\medskip
}
%----------------------------------------------------------------------------------------
% WARNING TEXT ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{warn}[optional title, defaults to "Warning:"]
% Contents
% \end{warn}
\mdfdefinestyle{warning}{
topline=false, bottomline=false,
leftline=false, rightline=false,
nobreak,
singleextra={%
\draw(P-|O)++(-0.5em,0)node(tmp1){};
\draw(P-|O)++(0.5em,0)node(tmp2){};
\fill[black,rotate around={45:(P-|O)}](tmp1)rectangle(tmp2);
\node at(P-|O){\color{white}\scriptsize\bf !};
\draw[very thick](P-|O)++(0,-1em)--(O);%--(O-|P);
}
}
% Define a custom environment for warning text
\newenvironment{warn}[1][Warning:]{ % Set the default warning to "Warning:"
\medskip
\begin{mdframed}[style=warning]
\noindent{\textbf{#1}}
}{
\end{mdframed}
}
%----------------------------------------------------------------------------------------
% INFORMATION ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{info}[optional title, defaults to "Info:"]
% contents
% \end{info}
\mdfdefinestyle{info}{%
topline=false, bottomline=false,
leftline=false, rightline=false,
nobreak,
singleextra={%
\fill[black](P-|O)circle[radius=0.4em];
\node at(P-|O){\color{white}\scriptsize\bf i};
\draw[very thick](P-|O)++(0,-0.8em)--(O);%--(O-|P);
}
}
% Define a custom environment for information
\newenvironment{info}[1][Info:]{ % Set the default title to "Info:"
\medskip
\begin{mdframed}[style=info]
\noindent{\textbf{#1}}
}{
\end{mdframed}
}
我想将左右文本对齐到与矩阵中包含的文本相同的高度。谢谢大家的帮助!
答案1
在tabstackengnine
包中,有一些宏可以根据指定的行间基线跳过来堆叠事物。这就是您在这里所需要的。
我展示了之前 (OP 代码) 和之后 (TABstacks)。但是,如果没有您的完整代码 (只有片段),我不会得到与您相同的错位bmatrix
。
请注意,如果某些矩阵的垂直范围比其他矩阵更高/更深,则 TABstack 行仍将对齐 - 但是,括号高度可能会有所不同(需要\vphantom
)。
\documentclass{article}
\usepackage{amsmath,tabstackengine}
\TABstackMath
%\TABstackMathstyle{\displaystyle}
\begin{document}
\begin{equation} \label{eqn:volt_hf_theta_esteemed}
\begin{bmatrix}
u_{dh}^{\hat{r}} \\
u_{qh}^{\hat{r}}
\end{bmatrix}
=
\begin{bmatrix}
j\omega_h \left(L_{avg} + \frac{L_\Delta}{2}cos(2\theta_\epsilon)\right) & j\omega_h \frac{L_\Delta}{2}sin(2\theta_\epsilon) \\
j\omega_h \frac{L_\Delta}{2}sin(2\theta_\epsilon) & j\omega_h \left(L_{avg} - \frac{L_\Delta}{2}cos(2\theta_\epsilon)\right)
\end{bmatrix}
\begin{bmatrix}
i_{dsh}^{\hat{r}} \\
i_{qsh}^{\hat{r}}
\end{bmatrix}
\end{equation}
\begin{equation}
\setstackgap{L}{18pt}
\setstacktabbedgap{6pt}
\bracketVectorstack{
u_{dh}^{\hat{r}} \\
u_{qh}^{\hat{r}}
}
=
\bracketMatrixstack{
j\omega_h \left(L_{avg} + \frac{L_\Delta}{2}cos(2\theta_\epsilon)\right) & j\omega_h \frac{L_\Delta}{2}sin(2\theta_\epsilon) \\
j\omega_h \frac{L_\Delta}{2}sin(2\theta_\epsilon) & j\omega_h \left(L_{avg} - \frac{L_\Delta}{2}cos(2\theta_\epsilon)\right)
}
\bracketVectorstack{
i_{dsh}^{\hat{r}} \\
i_{qsh}^{\hat{r}}
}
\end{equation}
\end{document}
使用 OP 现在提供的实际包/模板,在tabstackengine
对齐行数据的同时,确实必须\vphantom
在向量中添加一个以匹配括号大小。请注意,在这个 2 行的情况下,有人可能会认为的常量基线跳过功能tabstackengine
是不必要的,因为还必须使用 s \vphantom
。但是,如果矩阵高于 2 行,那么使用tabstackengine
将限制对\vphantom
在顶部和底部行,而不是每个矩阵的行,如下式2所示。
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[a4paper, 11pt]{article}
\usepackage{cite} % bibtex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lachaise Assignment
% Structure Specification File
% Version 1.0 (26/6/2018)
%
% This template originates from:
% http://www.LaTeXTemplates.com
%
% Authors:
% Marion Lachaise & François Févotte
% Vel ([email protected])
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\usepackage{amsmath,amsfonts,stmaryrd,amssymb,tabstackengine} % Math packages
\usepackage{enumerate} % Custom item numbers for enumerations
\usepackage[ruled]{algorithm2e} % Algorithms
\usepackage[framemethod=tikz]{mdframed} % Allows defining custom boxed/framed environments
\usepackage{listings} % File listings, with syntax highlighting
\lstset{
basicstyle=\ttfamily, % Typeset listings in monospace font
}
%----------------------------------------------------------------------------------------
% DOCUMENT MARGINS
%----------------------------------------------------------------------------------------
\usepackage{geometry} % Required for adjusting page dimensions and margins
\geometry{
paper=a4paper, % Paper size, change to letterpaper for US letter size
top=2.5cm, % Top margin
bottom=3cm, % Bottom margin
left=2.5cm, % Left margin
right=2.5cm, % Right margin
headheight=14pt, % Header height
footskip=1.5cm, % Space from the bottom margin to the baseline of the footer
headsep=1.2cm, % Space from the top margin to the baseline of the header
%showframe, % Uncomment to show how the type block is set on the page
}
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage{XCharter} % Use the XCharter fonts
%----------------------------------------------------------------------------------------
% COMMAND LINE ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{commandline}
% \begin{verbatim}
% $ ls
%
% Applications Desktop ...
% \end{verbatim}
% \end{commandline}
\mdfdefinestyle{commandline}{
leftmargin=10pt,
rightmargin=10pt,
innerleftmargin=15pt,
middlelinecolor=black!50!white,
middlelinewidth=2pt,
frametitlerule=false,
backgroundcolor=black!5!white,
frametitle={Command Line},
frametitlefont={\normalfont\sffamily\color{white}\hspace{-1em}},
frametitlebackgroundcolor=black!50!white,
nobreak,
}
% Define a custom environment for command-line snapshots
\newenvironment{commandline}{
\medskip
\begin{mdframed}[style=commandline]
}{
\end{mdframed}
\medskip
}
%----------------------------------------------------------------------------------------
% FILE CONTENTS ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{file}[optional filename, defaults to "File"]
% File contents, for example, with a listings environment
% \end{file}
\mdfdefinestyle{file}{
innertopmargin=1.6\baselineskip,
innerbottommargin=0.8\baselineskip,
topline=false, bottomline=false,
leftline=false, rightline=false,
leftmargin=2cm,
rightmargin=2cm,
singleextra={%
\draw[fill=black!10!white](P)++(0,-1.2em)rectangle(P-|O);
\node[anchor=north west]
at(P-|O){\ttfamily\mdfilename};
%
\def\l{3em}
\draw(O-|P)++(-\l,0)--++(\l,\l)--(P)--(P-|O)--(O)--cycle;
\draw(O-|P)++(-\l,0)--++(0,\l)--++(\l,0);
},
nobreak,
}
% Define a custom environment for file contents
\newenvironment{file}[1][File]{ % Set the default filename to "File"
\medskip
\newcommand{\mdfilename}{#1}
\begin{mdframed}[style=file]
}{
\end{mdframed}
\medskip
}
%----------------------------------------------------------------------------------------
% NUMBERED QUESTIONS ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{question}[optional title]
% Question contents
% \end{question}
\mdfdefinestyle{question}{
innertopmargin=1.2\baselineskip,
innerbottommargin=0.8\baselineskip,
roundcorner=5pt,
nobreak,
singleextra={%
\draw(P-|O)node[xshift=1em,anchor=west,fill=white,draw,rounded corners=5pt]{%
Question \theQuestion\questionTitle};
},
}
\newcounter{Question} % Stores the current question number that gets iterated with each new question
% Define a custom environment for numbered questions
\newenvironment{question}[1][\unskip]{
\bigskip
\stepcounter{Question}
\newcommand{\questionTitle}{~#1}
\begin{mdframed}[style=question]
}{
\end{mdframed}
\medskip
}
%----------------------------------------------------------------------------------------
% WARNING TEXT ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{warn}[optional title, defaults to "Warning:"]
% Contents
% \end{warn}
\mdfdefinestyle{warning}{
topline=false, bottomline=false,
leftline=false, rightline=false,
nobreak,
singleextra={%
\draw(P-|O)++(-0.5em,0)node(tmp1){};
\draw(P-|O)++(0.5em,0)node(tmp2){};
\fill[black,rotate around={45:(P-|O)}](tmp1)rectangle(tmp2);
\node at(P-|O){\color{white}\scriptsize\bf !};
\draw[very thick](P-|O)++(0,-1em)--(O);%--(O-|P);
}
}
% Define a custom environment for warning text
\newenvironment{warn}[1][Warning:]{ % Set the default warning to "Warning:"
\medskip
\begin{mdframed}[style=warning]
\noindent{\textbf{#1}}
}{
\end{mdframed}
}
%----------------------------------------------------------------------------------------
% INFORMATION ENVIRONMENT
%----------------------------------------------------------------------------------------
% Usage:
% \begin{info}[optional title, defaults to "Info:"]
% contents
% \end{info}
\mdfdefinestyle{info}{%
topline=false, bottomline=false,
leftline=false, rightline=false,
nobreak,
singleextra={%
\fill[black](P-|O)circle[radius=0.4em];
\node at(P-|O){\color{white}\scriptsize\bf i};
\draw[very thick](P-|O)++(0,-0.8em)--(O);%--(O-|P);
}
}
% Define a custom environment for information
\newenvironment{info}[1][Info:]{ % Set the default title to "Info:"
\medskip
\begin{mdframed}[style=info]
\noindent{\textbf{#1}}
}{
\end{mdframed}
}
%----------------------------------------------------------------------------------------
% ASSIGNMENT INFORMATION
%----------------------------------------------------------------------------------------
\title{Problem with matrix alignment}
\author{Not Sure \\ \texttt{[email protected]} \\ Number: \texttt{123456} }
\date{25th-Sep-2018}
\usepackage{tabstackengine}
\begin{document}
\maketitle
Equation (\ref{eqn:volt_hf_theta_esteemed}) is not aligned.
\begin{equation} \label{eqn:volt_hf_theta_esteemed}
\setstackgap{L}{22pt}
\bracketVectorstack{\vphantom{\Big(}
u_{dh}^{\hat{r}} \\
u_{qh}^{\hat{r}}
\vphantom{\Big)}}
=
\bracketMatrixstack{
j\omega_h \left(L_{avg} + \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right) & j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) \\
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) & j\omega_h \left(L_{avg} - \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right)
}
\bracketVectorstack{\vphantom{\Big(}
i_{dsh}^{\hat{r}} \\
i_{qsh}^{\hat{r}}
\vphantom{\Big)}}
\end{equation} % fix horiziontal alignment
\TABstackMathstyle{\displaystyle}
\begin{equation} \label{eqn:volt_hf_theta_esteemed}
\setstackgap{L}{30pt}
\bracketVectorstack{\vphantom{\bigg(}
u_{dh}^{\hat{r}} \\
u_{dh}^{\hat{r}} \\
u_{qh}^{\hat{r}}
\vphantom{\bigg)}}
=
\bracketMatrixstack{
j\omega_h \left(L_{avg} + \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right) & j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) \\
j\omega_h \left(L_{avg} + \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right) & j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) \\
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) & j\omega_h \left(L_{avg} - \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right)
}
\bracketVectorstack{\vphantom{\bigg(}
i_{dsh}^{\hat{r}} \\
i_{dsh}^{\hat{r}} \\
i_{qsh}^{\hat{r}}
\vphantom{\bigg)}}
\end{equation} % fix horiziontal alignment
\end{document}
答案2
\left
提供的和括号\right
太大。第一次尝试使用它们;第二次尝试使用\bigl
和\bigr
,这是本例中最佳的大小,但输出太拥挤;最后,第三种方法将两者混合使用。
\documentclass[a4paper, 11pt]{article}
\usepackage{amsmath}
\begin{document}
\section{With \texttt{\string\arraystretch}}
\begin{equation*}
\renewcommand{\arraystretch}{1.5}
\begin{bmatrix}
u_{dh}^{\hat{r}} \\
u_{qh}^{\hat{r}}
\end{bmatrix}
=
\begin{bmatrix}
j\omega_h \left((L_{\mathrm{avg}} + \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right)
&
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) \\
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon)
&
j\omega_h \left(L_{\mathrm{avg}} - \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\right)
\end{bmatrix}
\begin{bmatrix}
i_{dsh}^{\hat{r}} \\
i_{qsh}^{\hat{r}}
\end{bmatrix}
\end{equation*}
\section{With \texttt{\string\big}}
\begin{equation*}
\begin{bmatrix}
u_{dh}^{\hat{r}} \\
u_{qh}^{\hat{r}}
\end{bmatrix}
=
\begin{bmatrix}
j\omega_h \bigl((L_{\mathrm{avg}} + \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\bigr)
&
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) \\
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon)
&
j\omega_h \bigl(L_{\mathrm{avg}} - \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\bigr)
\end{bmatrix}
\begin{bmatrix}
i_{dsh}^{\hat{r}} \\
i_{qsh}^{\hat{r}}
\end{bmatrix}
\end{equation*}
\section{With \texttt{\string\big} \emph{and} \texttt{\string\arraystretch}}
\begin{equation*}
\renewcommand{\arraystretch}{1.2}
\begin{bmatrix}
u_{dh}^{\hat{r}} \\
u_{qh}^{\hat{r}}
\end{bmatrix}
=
\begin{bmatrix}
j\omega_h \bigl((L_{\mathrm{avg}} + \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\bigr)
&
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon) \\
j\omega_h \frac{L_\Delta}{2}\sin(2\theta_\epsilon)
&
j\omega_h \bigl(L_{\mathrm{avg}} - \frac{L_\Delta}{2}\cos(2\theta_\epsilon)\bigr)
\end{bmatrix}
\begin{bmatrix}
i_{dsh}^{\hat{r}} \\
i_{qsh}^{\hat{r}}
\end{bmatrix}
\end{equation*}
\end{document}