parbox 内的数学多条线

parbox 内的数学多条线

我收到了 parbox 中缺失}或丢失的多个错误$,其中有两行,但我不明白为什么......我已经整理了一个 MWE 来准确复制问题所在。

\documentclass{standalone}
\usepackage{color}
\def\df{\rule{0pt}{1.8ex}}

\begin{document}
\Large
\raisebox{+20.0pt}{%
  \fboxrule=2pt%
  \fcolorbox{blue}{white}{%
    \parbox[t][4.0cm]{8.0cm}{%
      \addvspace{0.5cm}\centering
      {\boldmath\color{blue}
      $\displaystyle
      {x} \;=\; -\, \frac{1}{k \,-\, 1}\,x_{\df{1}} \,+\,
      \frac{k}{k \,-\, 1}\,x_{\df{2}}
      $}\\[0.5cm]
      {\boldmath\color{blue}
      $\displaystyle
      {y} \;=\; -\, \frac{1}{k \,-\, 1 }\,y_{\df{1}} \,+\,
      \frac{k}{ k \,-\, 1 }\,y_{\df{2}}
      $}%
    }%
  }%
}%end raisebox
\;\;\textbf{.}
\end{document}

错误如下:

! Missing $ inserted.
<inserted text> 
                $
l.23 }
      %end raisebox
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

! Extra }, or forgotten $.
<recently read> }

l.23 }
      %end raisebox
I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Missing $ inserted.
<inserted text> 
                $
l.23 }
      %end raisebox
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

! Missing } inserted.
<inserted text> 
                }
l.23 }
      %end raisebox
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

答案1

您有太多的手动标记:很少需要\;\,有时很有用,但不适合您的用例。

使用aligned提供的amsmath。我还添加了\bfrac与减号粗细相匹配的分数线。为了降低下标,请使用空上标。

这个奇怪的border设置是为了解决似乎是一个错误的现象standalone;7pt 是半\fboxsep\fboxrule

\documentclass[border={-7pt 0 0 0}]{standalone}
\usepackage{amsmath,color}

\newcommand{\bfrac}[2]{%
  \genfrac{}{}{0.6pt}{}{#1}{#2}%
}

\begin{document}

\setlength{\fboxrule}{2pt}
\setlength{\fboxsep}{10pt}
\fcolorbox{blue}{white}{%
  \boldmath\color{blue}%
  $\!\begin{aligned}
   x &= - \bfrac{1}{k-1}x^{}_{1} + \bfrac{k}{k-1}x^{}_{2}
   \\
   y &= - \bfrac{1}{k-1}y^{}_{1} + \bfrac{k}{k-1}y^{}_{2}
  \end{aligned}$%
}

\end{document}

在此处输入图片描述

答案2

使用默认数学表达式\[ ... \]

\documentclass{standalone}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage{varwidth}
\begin{document}

{\Large\fboxrule=2pt\fboxsep=10pt
\fcolorbox{blue}{white}{%
\begin{varwidth}{\linewidth}
\[ x = -\frac{ 1 }{ k - 1 }\,x_1 + \frac{ k }{ k - 1 }\,x_2 \]
\[ y = -\frac{ 1 }{ k - 1 }\,y_1 + \frac{ k }{ k - 1 }\,y_2 \]
\end{varwidth}}%
}

\end{document}

在此处输入图片描述

相关内容