在矩陣元素之間繪製射線

在矩陣元素之間繪製射線

我想畫出下面的數學表達式。

想要的輸出

我對環境進行了很多嘗試tabular,但無法獲得想要的輸出。有人可以幫我解決這個問題嗎?

另一個問題是如何以以下方式繪製對角線:

  1. 在下式的行列式中X,射線來自1c 2和來自2c 1
  2. 在下式的行列式中y,射線來自c 1a2和來自c 2一個1
  3. 在 1 下的行列式中,光線來自一個12和來自a21

答案1

因此,在不知道您的文件類別或載入的套件的情況下,這個(誠然醜陋的)範例可能會解決您問題的第一部分:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
$\frac{x}{\begin{vmatrix}b_1&c_1\\ b_2&c_2 \end{vmatrix}}=\frac{y}{\begin{vmatrix} c_1&a_1 \\ c_2&a_2 \end{vmatrix}}=\frac{1}{\begin{vmatrix} a_1&b_1\\a_2&b_2 \end{vmatrix}}$

$\displaystyle\frac{x}{\begin{vmatrix}b_1&c_1\\ b_2&c_2 \end{vmatrix}}=\frac{y}{\begin{vmatrix} c_1&a_1 \\ c_2&a_2 \end{vmatrix}}=\frac{1}{\begin{vmatrix} a_1&b_1\\a_2&b_2 \end{vmatrix}}$
\end{document}

兩者之間的區別在於\displaystyle您可能喜歡也可能不喜歡。

答案2

從表3.6Latex 5.04 版本的簡短介紹,你會發現兩個符號\nearrow\searrow。您可以為行列式新增虛擬列和虛擬行(兩者皆位於中間),並將這兩個符號放在中間儲存格中。為了使它們重疊,我使用了負間距。這不是一個優雅的解決方案,但除了 amsmath 之外,您不需要任何其他軟體包。我還有另一個基於raiseboxfrom 的不太優雅的解決方案https://en.wikibooks.org/wiki/LaTeX/Boxes#raisebox

\documentclass[12pt,a5paper]{article}
\usepackage{amsmath}
\begin{document}
a\\
\(
\begin{vmatrix}
b_1 & & c_1\\
& \nearrow \hspace{-1em} \searrow &\\
b_2 & & c_2\\
\end{vmatrix}
\)
\\
%another solution
\(
\begin{vmatrix}
b_1 & & c_1\\
b_2 & & c_2\\
\end{vmatrix}
\)
\hspace{-3.2em} \raisebox{-0.3ex}\text{{$\nearrow$}}
\hspace{-1.7em} \raisebox{-0.3ex}\text{{$\searrow$}} 
\end{document}

在此輸入影像描述

答案3

從使用者 jfbu 複製貼上的程式碼回答在矩陣元素之間繪製射線。相當拗口,但它避免了大型圖形引擎。每次需要兩次編譯。與 一起工作pdflatex

\documentclass{article}

% from https://tex.stackexchange.com/a/277474/4686 (user jfbu)
% --------------------------------START--------------------------------
% matrices
\usepackage{amsmath}

% I discovered a bad interaction of eso-pic with xetex
% which is fixed for an unknown reason to me by loading
% package geometry
\usepackage{geometry}

% transforms the page into a LaTeX picture
\usepackage{eso-pic}

% enhances original LaTeX picture
% there are other packages
% unfortunately I don't know how to draw dashed lines with pict2e
\usepackage{pict2e}

% for some color
\usepackage{color}

\makeatletter
\newbox\JayBox
\def\JayNodeCount{0}%

\def\zapspaces #1 #2{#1#2\zapspaces }

\newcommand\Node [2]{%
% make the code work also if no amsmath
    \ifcsname ifmeasuring@\endcsname
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
    {\unless\ifmeasuring@}\iftrue
      \xdef\JayNodeCount{\the\numexpr\JayNodeCount+\@ne}%
      \ifcsname JAY@nodecoords@\romannumeral\JayNodeCount\endcsname
        \global
        \expandafter\let
        \csname JAY@nodename@\expandafter\zapspaces\detokenize{#1} \@gobble
        \expandafter\endcsname
        \csname JAY@nodecoords@\romannumeral\JayNodeCount\endcsname
      \else\typeout{========> New JAY node: run LaTeX again ! <========}%
      \fi
         \sbox\JayBox{$\m@th #2$}%
      \pdfsavepos
         \edef\JAY@temp{%
              \global
              \def\@backslashchar
                          JAY@nodecoords@\romannumeral\JayNodeCount
                  {{\noexpand\the\numexpr\pdflastxpos+\number\wd\JayBox/2}%
                   {\noexpand\the\numexpr\pdflastypos+\number\ht\JayBox/2}%
                   {\number\wd\JayBox/2}{\number\ht\JayBox/2}}%
                       }%
         \write\@mainaux\expandafter{\JAY@temp}%
    \fi
    #2%
}%

\def\JAY@north{north}
\def\JAY@south{south}
\def\JAY@west {west}
\def\JAY@east {east}
\def\JAY@northwest{northwest}
\def\JAY@northeast{northeast}
\def\JAY@southeast{southeast}
\def\JAY@southwest{southwest}


\def\JAY@setupAnode #1#2#3#4%
{%
    \def\JAY@Ax {#1}\def\JAY@Ay {#2}\def\JAY@Adx {#3}\def\JAY@Ady {#4}%
    \ifx\JAY@Aspec\JAY@north\edef\JAY@Ay {\the\numexpr\JAY@Ay+\JAY@Ady}\fi
    \ifx\JAY@Aspec\JAY@south\edef\JAY@Ay {\the\numexpr\JAY@Ay-\JAY@Ady}\fi
    \ifx\JAY@Aspec\JAY@west \edef\JAY@Ax {\the\numexpr\JAY@Ax-\JAY@Adx}\fi
    \ifx\JAY@Aspec\JAY@east \edef\JAY@Ax {\the\numexpr\JAY@Ax+\JAY@Adx}\fi
    \ifx\JAY@Aspec\JAY@northwest
                   \edef\JAY@Ay {\the\numexpr\JAY@Ay+\JAY@Ady}%
                   \edef\JAY@Ax {\the\numexpr\JAY@Ax-\JAY@Adx}%
    \fi
    \ifx\JAY@Aspec\JAY@northeast
                   \edef\JAY@Ay {\the\numexpr\JAY@Ay+\JAY@Ady}%
                   \edef\JAY@Ax {\the\numexpr\JAY@Ax+\JAY@Adx}%
    \fi
    \ifx\JAY@Aspec\JAY@southeast
                   \edef\JAY@Ay {\the\numexpr\JAY@Ay-\JAY@Ady}%
                   \edef\JAY@Ax {\the\numexpr\JAY@Ax+\JAY@Adx}%
    \fi
    \ifx\JAY@Aspec\JAY@southwest
                   \edef\JAY@Ay {\the\numexpr\JAY@Ay-\JAY@Ady}%
                   \edef\JAY@Ax {\the\numexpr\JAY@Ax-\JAY@Adx}%
    \fi
}%

\def\JAY@setupBnode #1#2#3#4%
{%
    \def\JAY@Bx {#1}\def\JAY@By {#2}\def\JAY@Bdx {#3}\def\JAY@Bdy {#4}%
    \ifx\JAY@Bspec\JAY@north\edef\JAY@By {\the\numexpr\JAY@By+\JAY@Bdy}\fi
    \ifx\JAY@Bspec\JAY@south\edef\JAY@By {\the\numexpr\JAY@By-\JAY@Bdy}\fi
    \ifx\JAY@Bspec\JAY@west \edef\JAY@Bx {\the\numexpr\JAY@Bx-\JAY@Bdx}\fi
    \ifx\JAY@Bspec\JAY@east \edef\JAY@Bx {\the\numexpr\JAY@Bx+\JAY@Bdx}\fi
    \ifx\JAY@Bspec\JAY@northwest
                   \edef\JAY@By {\the\numexpr\JAY@By+\JAY@Bdy}%
                   \edef\JAY@Bx {\the\numexpr\JAY@Bx-\JAY@Bdx}%
    \fi
    \ifx\JAY@Bspec\JAY@northeast
                   \edef\JAY@By {\the\numexpr\JAY@By+\JAY@Bdy}%
                   \edef\JAY@Bx {\the\numexpr\JAY@Bx+\JAY@Bdx}%
    \fi
    \ifx\JAY@Bspec\JAY@southeast
                   \edef\JAY@By {\the\numexpr\JAY@By-\JAY@Bdy}%
                   \edef\JAY@Bx {\the\numexpr\JAY@Bx+\JAY@Bdx}%
    \fi
    \ifx\JAY@Bspec\JAY@southwest
                   \edef\JAY@By {\the\numexpr\JAY@By-\JAY@Bdy}%
                   \edef\JAY@Bx {\the\numexpr\JAY@Bx-\JAY@Bdx}%
    \fi
}%

\newcommand\NodeLine [2][]{\def\JAY@opt{#1}\JAY@NodeLine #2\JAY@NodeLine}

\def\JAY@NodeLine #1[#2]#3->#4[#5]#6\JAY@NodeLine
{%
    \edef\JAY@nodeA {\expandafter\zapspaces\detokenize{#1} \@gobble}%
    \edef\JAY@nodeB {\expandafter\zapspaces\detokenize{#4} \@gobble}%
    \let\JAY@temp\empty
    \ifcsname JAY@nodename@\JAY@nodeA\endcsname
    \ifcsname JAY@nodename@\JAY@nodeB\endcsname
       \edef\JAY@Aspec {\zapspaces #2 \@gobble}%
       \edef\JAY@Bspec {\zapspaces #5 \@gobble}%
       \expandafter\expandafter\expandafter
            \JAY@setupAnode\csname JAY@nodename@\JAY@nodeA\endcsname
       \expandafter\expandafter\expandafter
            \JAY@setupBnode\csname JAY@nodename@\JAY@nodeB\endcsname
    \edef\JAY@temp {%
     \noexpand\AddToShipoutPictureFG*{%
% THIS IS THE ONLY PLACE WHERE THE PICTURE SYNTAX IS USED
% here we use \Line from package pict2e
% The optional argument to \NodeLine contains optional commands
       {\setlength{\unitlength}{1sp}%
       \linethickness{1pt}%
       \unexpanded\expandafter{\JAY@opt}%
       \noexpand\Line (\JAY@Ax,\JAY@Ay)(\JAY@Bx,\JAY@By)%
                   }}}%
    \fi\fi
  \JAY@temp
}
\makeatother
% --------------------------------FINISH-------------------------------

\begin{document}

\Huge

\[\frac{x}
  {\begin{vmatrix}\Node{B1}{b_1}&\Node{C1}{c_1}\\
    \Node{B2}{b_2}&\Node{C2}{c_2}\end{vmatrix}}
=
  \frac{y}
  {\begin{vmatrix} 
    \Node{C1y}{c_1}&\Node{A1y}{a_1} \\
    \Node{C2y}{c_2}&\Node{A2y}{a_2} \end{vmatrix}}
=
   \frac{1}
    {\begin{vmatrix}
    a_1&b_1\\a_2&b_2 \end{vmatrix}}
\]
% No need to be inside the display, but
% make sure to issue these commands on the same page !

% TWO COMPILATIONS NEEDED AFTER ANY MODIFICATION

\NodeLine[\color{blue}]{B1[south east] -> C2[north west]}
\NodeLine[\color{red}] {C1[south west]-> B2[north east]}
% for some reason B2[east] gives more pleasing result than B2[north east]
% note that B2 alone does not work, must be B2[]

\NodeLine[\color{green}]{C1y[] -> A2y[]}
\NodeLine[\color{magenta}] {A1y[]-> C2y[]}

\end{document}

區塊引用

相關內容