
이게 정말 좋은 생각인지 아닌지는 모르겠지만 \frac
정렬 탭( )에서 분자와 분모를 정렬할 수 있는 버전을 구현하는 것이 가능한지 궁금합니다 &
.
이 사이트에는 분수 정렬에 대한 많은 질문이 있으며, 많은 경우에 가장 확실한 해결책은 를 사용하는 것입니다 \hfill
. 하지만 다음과 같은 분수를 생각해 보세요.
내 눈에는 맨 위가 약간 지저분해 보이지만 를 사용하면 \hfill
분자가 너무 왼쪽으로 이동합니다. 내가 정말로 원하는 것은 열린 괄호에 정확하게 정렬하는 것입니다. 그래서 저는 \alignedfrac
제가 글을 쓸 수 있게 해주는 명령을 상상하고 있습니다.
\[
\alignedfrac{q&(x\mid y)}{p_\mathrm{foo}&(w\mid x,y,z)}
\]
문자 의 분자와 분모를 정렬합니다 &
.
나는 이것이 실제로 좋은 선택일 수도 있고 아닐 수도 있다는 것을 알고 있으며 아마도 문제가 아닌 문제를 해결하고 있지만 그래도 이와 같은 구현이 가능한지 궁금합니다.
위의 이미지를 생성하는 MWE는 다음과 같습니다.
\documentclass{article}
\begin{document}
\noindent without any alignment:
\[
\frac{q(x\mid y)}{p_\mathrm{foo}(w\mid x,y,z)}
\]
using hfill:
\[
\frac{q(x\mid y)\hfill}{p_\mathrm{foo}(w\mid x,y,z)}
\]
\end{document}
답변1
여기서는 부분 정렬을 달성하기 위해 s를 사용하여 frac의 왼쪽 부분( \leftfrac
)과 오른쪽 부분( \rightfrac
)을 독립적으로 구성합니다. \hfill
그런 다음 둘 사이에 음수를 사용하여 두 가지를 인접하게 조판했습니다 \mkern
.
Mico의 제안에 따라 더 나은 모양을 위해 |
가 로 대체되었습니다 \mid
.
일치를 추가하도록 편집되었습니다 \vphantom
. 왼쪽과 오른쪽 부분의 수직 범위가 다른 경우 도움이 될 것이라고 생각합니다.
\documentclass{article}
\begin{document}
\newcommand\alignedfrac[2]{%
\leftfrac#1\\#2\relax\mkern-4.5mu\rightfrac#1\\#2\relax
}
\def\leftfrac#1\\#3\relax{%
\frac{\hfill#1\vphantom{#2}}{\hfill#3\vphantom{#4}}}
\def\rightfrac#1\\#3\relax{%
\frac{\vphantom{#1}#2\hfill}{\vphantom{#3}#4\hfill}}
\noindent without any alignment:
\[
\frac{q(x\mid y)}{p_\mathrm{foo}(w\mid x,y,z)}
\]
using hfill:
\[
\frac{q(x\mid y)\hfill}{p_\mathrm{foo}(w\mid x,y,z)}
\]
using alignedfrac
\[
\alignedfrac{q&(x\mid y)}{p_\mathrm{foo}&(w\mid x,y,z)}
\]
\end{document}
답변2
할 수 있어요:
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\alignedfrac}[2]{%
\begingroup
\setbox0=\vbox{%
\m@th
\ialign{&$\displaystyle##$\cr#1\cr#2\cr}%
\setbox2=\lastbox
\hbox{%
\unhbox2
\unskip
\setbox4=\lastbox
\unskip
\setbox6=\lastbox
\global\dimen1=\wd6
\global\dimen3=\wd4
}
}
\frac{\af@make#1\@nil}{\af@make#2\@nil}
\endgroup
}
\def\af@make#1\@nil{%
\makebox[\dimen1][r]{$\displaystyle#1$}%
\makebox[\dimen3][l]{$\displaystyle#2$}%
}
\makeatother
\begin{document}
\begin{gather*}
\alignedfrac{q&(x\mid y)}{p_\mathrm{foo}&(w\mid x,y,z)} \\
\frac{q(x\mid y)}{p_\mathrm{foo}(w\mid x,y,z)}
\end{gather*}
\end{document}
무슨 일이야? 나는 프리미티브와 정렬을 한 \halign
다음 빌드된 상자를 분해하여 마지막 행을 검사합니다. 두 부분의 치수를 저장하고 이를 사용하여 적절한 너비의 상자를 만듭니다.
그러나 이미지에서 명확하게 볼 수 있듯이 표준 분수와 관련하여 개선이 보이지 않습니다.