在数学模式中左对齐特定文本

在数学模式中左对齐特定文本

我目前有

在此处输入图片描述

通过

\documentclass{scrartcl}
\KOMAoptions{
  fontsize = 10pt   ,
  headings = normal ,
}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{siunitx}
\begin{document}
\begin{multicols*}{2}
\section*{Electric Charge}
\textsf{Coulomb's Law} describes the electrostatic force between point electric charges $q_1$ and $q_2$ at (or nearly at) rest and separated by distance r:
%
\begin{align}
  F_c &= \frac{1}{4\pi\epsilon_0}\frac{|q_1||q_2|}{r^2} = \frac{k|q_1||q_2|}{r^2}\\
  \text{where} \quad e_0 &= \SI{8.85e-12}{\coulomb\squared\per\newton\per\meter\squared}\\
  \text{and} \quad k &= \SI{8.99e9}{\newton\meter\squared\per\coulomb\squared}
\end{align}
\end{multicols*}
\end{document}

并希望制作以下内容:

Coulomb's Law describes the electrostatic force
between point electric charges q1 and q2 at (or
nearly at) rest and separated by distance r:

           F = (1/4πe_0)(|q1||q2|)/r^2      (1)
where     e0 = 8.85*10^-12 C^2/N*m^2        (2)
and        k = 8.99*10^9 N*m^2/C^2          (3)

在数学模式下,我该如何左对齐特定文本(例如,通过命令)以使文本尽可能向左移动?我希望在数学模式下保留默认的居中样式。

答案1

考虑到有效的文本度量相当狭窄,我不禁感到这个例子非常适合使用该包(该包的超集)\shortintertext提供的命令。mathtoolsamsmath

\documentclass{scrartcl}
\KOMAoptions{fontsize = 10pt, headings = normal}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{siunitx}
\newcommand{\abs}[1]{\lvert#1\rvert}
\begin{document}
\begin{multicols*}{2}
\section*{Electric Charge}
\textsf{Coulomb's Law} describes the electrostatic force between 
point electric charges $q_1$ and $q_2$ at (or nearly at) rest and 
separated by distance~$r$:
\begin{align}
  F_c &= \frac{1}{4\pi\epsilon_0}\frac{\abs{q_1}\abs{q_2}}{r^2} 
          = \frac{k\abs{q_1}\abs{q_2}}{r^2}\\
\shortintertext{where}
  e_0 &= \SI{8.85e-12}{\coulomb\squared\per\newton\per\meter\squared}\\
\shortintertext{and}
   k &= \SI{8.99e9}{\newton\meter\squared\per\coulomb\squared}\,.
\end{align}
\end{multicols*}
\end{document}

在此处输入图片描述

答案2

这不是问题的答案。不过我认为你可以选择一些在重点方面不那么分散注意力的东西(个人意见!)。目前它们看起来像额外的方程式,我们试图在单位中找到右侧的变量。

\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{multicol}
\usepackage{siunitx,lipsum}
\setlength\textwidth{15cm}
\begin{document}
\begin{multicols*}{2}
\textsf{Coulomb's Law} describes the electrostatic 
force between point electric charges $q_1$ and 
$q_2$ at (or nearly at) rest and separated by distance $r$:
%
\begin{equation}
  F_c = \frac{1}{4\pi\epsilon_0}\frac{|q_1||q_2|}{r^2} = \frac{k|q_1||q_2|}{r^2}
\end{equation}
where $e_0 = \SI{8.85e-12}{\coulomb\squared\per\newton\per\meter\squared}$ and 
$k = \SI{8.99e9}{\newton\meter\squared\per\coulomb\squared}$.

\textsf{Coulomb's Law} describes the electrostatic 
force between point electric charges $q_1$ and 
$q_2$ at (or nearly at) rest and separated by distance r:
\begin{align}
  F_c &= \frac{1}{4\pi\epsilon_0}\frac{|q_1||q_2|}{r^2} = \frac{k|q_1||q_2|}{r^2}\\
\shortintertext{where}
e_0 &= \SI{8.85e-12}{\coulomb\squared\per\newton\per\meter\squared} \notag\\
k &= \SI{8.99e9}{\newton\meter\squared\per\coulomb\squared}.\notag
\end{align}

\lipsum[1-4]
\end{multicols*}

\end{document}

在此处输入图片描述

如果数值不重要,则第一个方法将常量完全埋入文本中;如果我们想关注这些数字,则第二个方法为这些数字提供独立的空间。

答案3

amsmath环境flalign非常适合这种情况,将元素向外(左和右)对齐:

在此处输入图片描述

\documentclass{article}
\usepackage[margin=1in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{multicol}% http://ctan.org/pkg/multicol
\usepackage{siunitx}% http://ctan.org/pkg/siunitx
\begin{document}
\begin{multicols*}{2}
\textsf{Coulomb's Law} describes the electrostatic force between point electric charges $q_1$ and $q_2$ at (or nearly at) rest and separated by distance r:
%
\begin{flalign}
  && F_c &= \frac{1}{4\pi\epsilon_0}\frac{|q_1||q_2|}{r^2} = \frac{k|q_1||q_2|}{r^2} && \\
  \text{where} && e_0 &= \SI{8.85e-12}{\coulomb\squared\per\newton\per\meter\squared} &&\\
  \rlap{\text{and}}\phantom{\text{where}} && k &= \SI{8.99e9}{\newton\meter\squared\per\coulomb\squared} &&
\end{flalign}
\end{multicols*}
\end{document}

添加geometry是为了复制原始帖子中的输出。更具体地说,它被用来扩大multicol但最终输出中可能不需要这些列。此外,使用\nonumber将删除那些不需要数字的方程的方程编号(例如,(2) 和 (3))。

答案4

有同样的问题(有更具体的要求)公式中的文本左对齐。我得到的最终解决方案涉及修补一些amsmath内容并创建命令\beforetext

\documentclass[a5paper]{article}
\usepackage{amsmath,etoolbox} 
\usepackage{siunitx}

\makeatletter
\newif\if@gather@prefix 
\preto\place@tag@gather{% 
  \if@gather@prefix\iftagsleft@ 
    \kern-\gdisplaywidth@ 
    \rlap{\gather@prefix}% 
    \kern\gdisplaywidth@ 
  \fi\fi 
} 
\appto\place@tag@gather{% 
  \if@gather@prefix\iftagsleft@\else 
    \kern-\displaywidth 
    \rlap{\gather@prefix}% 
    \kern\displaywidth 
  \fi\fi 
  \global\@gather@prefixfalse 
} 
\preto\place@tag{% 
  \if@gather@prefix\iftagsleft@ 
    \kern-\gdisplaywidth@ 
    \rlap{\gather@prefix}% 
    \kern\displaywidth@ 
  \fi\fi 
} 
\appto\place@tag{% 
  \if@gather@prefix\iftagsleft@\else 
    \kern-\displaywidth 
    \rlap{\gather@prefix}% 
    \kern\displaywidth 
  \fi\fi 
  \global\@gather@prefixfalse 
} 
\def\math@cr@@@align{%
  \ifst@rred\nonumber\fi
  \if@eqnsw \global\tag@true \fi
  \global\advance\row@\@ne
  \add@amps\maxfields@
  \omit
  \kern-\alignsep@
  \if@gather@prefix\tag@true\fi
  \iftag@
    \setboxz@h{\@lign\strut@{\make@display@tag}}%
    \place@tag
  \fi
  \ifst@rred\else\global\@eqnswtrue\fi
  \global\lineht@\z@
  \cr
}
\newcommand*{\beforetext}[1]{% 
  \ifmeasuring@\else
  \gdef\gather@prefix{#1}% 
  \global\@gather@prefixtrue 
  \fi
} 
\makeatother

\begin{document}
\textsf{Coulomb's Law} describes the electrostatic force between point electric charges $q_1$ and $q_2$ at (or nearly at) rest and separated by distance $r$:
\begin{align}
  F_c &= \frac{1}{4\pi\epsilon_0}\frac{|q_1||q_2|}{r^2} = \frac{k|q_1||q_2|}{r^2}\\
  \beforetext{where} \epsilon_0 &= \SI{8.85e-12}{\coulomb\squared\per\newton\per\meter\squared}\\
  \beforetext{and} k &= \SI{8.99e9}{\newton\meter\squared\per\coulomb\squared}
\end{align}
\end{document}

在此处输入图片描述

注意:如果这是您正在使用的真实文本,您可能希望使用$r$而不是r\epsilon_0而不是e_0

与使用相比,其优点flalign在于它gather也可以与一起使用,并且您不需要更改方程的正常编码。

相关内容