如何使 from= , to= 參數在 Tikzcd 中以相容模式工作?

如何使 from= , to= 參數在 Tikzcd 中以相容模式工作?

由於某種原因,在不破壞我文檔中其他內容的情況下修復這可能需要太多工作,Tikzcd 只能在我的文檔中以兼容模式使用“箭頭的替代語法”,根據手冊,“箭頭的替代語法」是「在出現之前使用的」。標籤的引號語法」。

這意味著程式碼如下:

\arrow[r, Rightarrow, "\phi"]

在我的文檔中不起作用,我必須將其寫入:

 \arrow[Rightarrow]{r}{\phi}

才能得到預期的結果。

那麼我該如何寫出[from=A,to=B] 出現在以下情況的表達式:

\documentclass{article} 
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
   A \arrow[r, bend left=50, ""{name=U, below, draw=red}]
   \arrow[r, bend right=50, ""{name=D, draw=red}]
   & B
   \arrow[Rightarrow, from=U, to=D]
\end{tikzcd}
\end{document}

更具體地說,我嘗試使以下表達式起作用:

\documentclass{article} 
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
    \mathcal{C}
    \ar[bend left=47, pos=0.5]{r}{F}
    \ar[bend right=47, pos=0.5]{r}[swap]{G}
    \arrow[phantom,bend left=40, shift right=0.2ex, name=U]{r}
    \arrow[phantom,bend right=38.4, shift left=0.2ex, swap, name=D]{r}
    &   \mathcal{D}
    \arrow[Rightarrow]{from=U,to=D}{N}
\end{tikzcd}
\end{document}

但是最後一個箭頭應該從上箭頭的中間向下到下箭頭的中間給出了錯誤,並且錯誤地顯示為稍微向上傾斜的左向箭頭。也就是說,我得到的結果是: 在此輸入影像描述

當我想要這樣的東西時:

在此輸入影像描述

但當然會顯示其他名稱。

答案1

根據tikz-cd手動的,除了使用可以透過相關單元格內的選項分配的節點名稱(請參見下面的第二個範例)之外,您還可以在使用和選項時alias使用語法<row number>-<column number>來表示箭頭的開始和結束(請參見下面的第一個範例) 。然而,這些選項應該放在可選參數內。您也可以使用或移動箭頭。fromtoxshiftyshift

\documentclass[border=10pt, tikz]{standalone} 
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
    \mathcal{C}
    \arrow[bend left=47, pos=0.5]{r}{F}
    \arrow[bend right=47, pos=0.5]{r}[swap]{G}
    &  \mathcal{D}
    \arrow[Rightarrow, from=1-2, to=1-1, yshift=0.5pt]{}{N}
\end{tikzcd}
\end{document}
\documentclass[border=10pt, tikz]{standalone} 
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
    |[alias=R]| \mathcal{C}
    \arrow[bend left=47, pos=0.5]{r}{F}
    \arrow[bend right=47, pos=0.5]{r}[swap]{G}
    & |[alias=L]| \mathcal{D}
    \arrow[Rightarrow, from=L, to=R, yshift=0.5pt]{}{N}
\end{tikzcd}
\end{document}

兩個程式碼片段產生相同的輸出:

在此輸入影像描述


現在,新增向下箭頭並不是太直接,因為描述箭頭起點和終點的兩個座標不是可以透過上述策略選擇的儲存格。但是,您可以稍微擴展矩陣,如下例所示:

\documentclass[border=10pt, tikz]{standalone} 
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
    & {} & \\
    \mathcal{O}(X)^{op}
    \arrow[bend left=47, pos=0.5]{rr}{\Lambda A}
    \arrow[bend right=47, pos=0.5]{rr}[swap]{\Lambda A'}
    &  & \textbf{Set} \\
    & {} & 
    \arrow[Rightarrow, from=1-2, to=3-2, 
        shorten >=5pt, shorten <=5pt, xshift=-3.5pt]
        {}{\Lambda f}
\end{tikzcd}
\end{document}

在此輸入影像描述


或者,您可以使用start anchorend anchor選項,但不知何故,下彎曲箭頭的標籤被錯誤地放置在如此小的尺寸中:

\documentclass[border=10pt, tikz]{standalone} 
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
    |[alias=R]| \mathcal{O}(X)^{op}
    \arrow[bend left=47, pos=0.5]{r}{\Lambda A}
    \arrow[bend right=47, pos=0.5]{r}[swap]{\Lambda A'}
    & |[alias=L]| \textbf{Set}
    \arrow[Rightarrow, from=L, to=L, 
        start anchor={[xshift=-1cm]north}, end anchor={[xshift=-1cm]south}]
        {}{\Lambda f}
\end{tikzcd}
\end{document}

在此輸入影像描述

可以透過向每個單元格添加 a 來固定標籤的位置,\strut使它們等大:

\documentclass[border=10pt, tikz]{standalone} 
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
    |[alias=R]| \mathcal{O}(X)^{op}\strut
    \arrow[bend left=47, pos=0.5]{r}{\Lambda A}
    \arrow[bend right=47, pos=0.5]{r}[swap]{\Lambda A'}
    & |[alias=L]| \textbf{Set}\strut
    \arrow[Rightarrow, from=L, to=L, 
        start anchor={[xshift=-1cm]north}, end anchor={[xshift=-1cm]south}]
        {}{\Lambda f}
\end{tikzcd}
\end{document}

在此輸入影像描述

答案2

讓我建議一條不同的路線,它可以讓您:

  • 處理您的文檔,該文檔無法處理最新tikz-cd版本
  • 使用最新tikz-cd版本時

這個方法是在空間上分離需求,即這個在一個地方,那個在不同的地方:

  • 處理您的主文檔,該文檔使用incompatible documentclass
  • 根據類別standalone處理盡可能多的文檔,每個文檔代表一個圖表

開始了:

箭頭.tex,這是您發布的程式碼,稍有改動。只需編譯它,我們arrows.pdf稍後會回來。

\documentclass[10pt,border=3mm]{standalone}
    %\documentclass{article} 
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
   A \arrow[r, bend left=50, ""{name=U, below, draw=red}]
   \arrow[r, bend right=50, ""{name=D, draw=red}]
   & B
   \arrow[Rightarrow, from=U, to=D]
\end{tikzcd}
\end{document}

箭頭


主文件,它使用了一個不尋常的文檔類,比方說screenplay:這模仿了差異、缺點、不相容性等tikz-cd

劇本甚至可以與 tikz-cd 一起使用,我沒有檢查。但讓我們假裝,事實並非如此。正如你所看到的,它根本不使用任何 Tikz 方言...

相關程式碼行是:

...
\usepackage{graphicx}       % without tikz showing tikz-cd diagram
...
    \includegraphics[width=.3\textwidth]{arrows}% i.e. arrows.pdf
...

戲劇

\documentclass{screenplay}[2012/06/30]  % just an alian class
\usepackage{graphicx}       % without tikz showing tikz-cd diagram

% ~~~ some shortcuts ~~~~~~~~~~~~
\newcommand\di[2]{\begin{dialogue}{#1}#2\end{dialogue}}
\newcommand\dia[3]{\begin{dialogue}[#2]{#1}#3\end{dialogue}}
\newcommand\newch[1]{\MakeUppercase{#1}}
\newcommand\pr[0]{Proggi}
\newcommand\ld[0]{Lad}

% ~~~ some redefine ~~~~~~~~~~~
\renewcommand\emph{***}

% ~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}

 \title{An arrows drama}
 \author{MS-SPO}
 \maketitle

 % ~~~ Characters ~~~~~~~~~~~~~~~~~~~~~~
 \newch{Proggi}, a programmer, full of energy.

 \newch{Lad}, a nice document creating language, with some bells and whistles.

 % ~~~ Let the drama begin ~~~~~~~~~~~
 \fadein

 \intslug[Night]{A stubborn documentclass}
 \pr{} spent already endless hours, while \ld{} keeps being stubborn.

 \dia{\pr}{impatient}{Why can't you just do what I'm telling you to do! Why can't you?}

 \dia{\ld}{amused}{You did read the manuals, did you?}

 \dia{\pr}{about to burst}{Yours, yeah \dots other ones?}

 \dia{\ld}{whispering}{Yes: about \emph{standalone} and \emph{graphicx} \dots There you go \dots}

\begin{center}
    \includegraphics[width=.3\textwidth]{arrows}   % <<<
\end{center}


 \fadeout
\end{document}

相關內容