将文本环绕在 tikz-cd 图表周围时将其向上移动

将文本环绕在 tikz-cd 图表周围时将其向上移动

我想tikz-cd在文本旁边添加一个图表,并将其环绕起来。为此,我使用了包wrapfig。代码如下:

\documentclass[psamsfonts]{amsart}

\usepackage{quiver}
\usepackage{tikz-cd}
\usepackage{wrapfig}
\tikzcdset{scale cd/.style={every label/.append style={scale=#1},
    cells={nodes={scale=#1}}}}

\title{}
\author{}
\date{}
\begin{document}

\begin{abstract}
...
\end{abstract}
\maketitle
\tableofcontents

\begin{wrapfigure}{r}{5cm}
\begin{tikzcd}[column sep=9pt, scale cd=0.9]
\end{tikzcd}
\end{wrapfigure}
Given a short exact sequence of cochain complexes...

\end{document}

输出如下所示:

在此处输入图片描述

图表上方有大量空白,当我向左侧添加文本时,空白量会增加。我怎样才能只将图表向上移动?

完整的可编译代码:

\documentclass[psamsfonts]{amsart}

\usepackage{quiver}
\usepackage{tikz-cd}
\usepackage{wrapfig}
\usepackage{lipsum}
\tikzcdset{scale cd/.style={every label/.append style={scale=#1},
    cells={nodes={scale=#1}}}}

\title{}
\author{}
\date{}
\begin{document}

\begin{abstract}
...
\end{abstract}
\maketitle
\tableofcontents

\begin{wrapfigure}{r}{5cm}
\begin{tikzcd}[column sep=9pt, scale cd=0.9]
    && \vdots && \vdots && \vdots \\
    \\
    0 && {A^{k+1}} && {B^{k+1}} && {C^{k+1}} && 0 \\
    \\
    0 && {A^{k}} && {B^k} && {C^{k}} && 0 \\
    \\
    0 && {A^{k-1}} && {B^{k-1}} && {C^{k-1}} && 0 \\
    \\
    && \vdots && \vdots && \vdots
    \arrow[from=5-7, to=5-9]
    \arrow["j", from=5-5, to=5-7]
    \arrow["i", from=5-3, to=5-5]
    \arrow[from=5-1, to=5-3]
    \arrow[from=7-1, to=7-3]
    \arrow["i", from=7-3, to=7-5]
    \arrow["j", from=7-5, to=7-7]
    \arrow[from=7-7, to=7-9]
    \arrow["d_A", shorten <=3pt, shorten >=3pt, from=5-3, to=3-3]
    \arrow["d_B", shorten <=3pt, shorten >=3pt, from=5-5, to=3-5]
    \arrow["d_C", shorten <=3pt, shorten >=3pt, from=5-7, to=3-7]
    \arrow["d_C", shorten <=3pt, shorten >=3pt, from=7-7, to=5-7]
    \arrow["d_B", shorten <=3pt, shorten >=3pt, from=7-5, to=5-5]
    \arrow["d_A", shorten <=3pt, shorten >=3pt, from=7-3, to=5-3]
    \arrow[from=9-3, to=7-3]
    \arrow[from=9-5, to=7-5]
    \arrow[from=9-7, to=7-7]
    \arrow[from=3-7, to=3-9]
    \arrow["j", from=3-5, to=3-7]
    \arrow["i", from=3-3, to=3-5]
    \arrow[from=3-1, to=3-3]
    \arrow[from=3-3, to=1-3]
    \arrow[from=3-5, to=1-5]
    \arrow[from=3-7, to=1-7]
\end{tikzcd}
\end{wrapfigure}
\lipsum

\end{document}

答案1

在此处输入图片描述

\documentclass[psamsfonts]{amsart}

% \usepackage{quiver}
\usepackage{tikz-cd}
\usepackage{wrapfig}
\usepackage{lipsum}
\tikzcdset{scale cd/.style={every label/.append style={scale=#1},
    cells={nodes={scale=#1}}}}

\title{}
\author{}
\date{}
\setlength\intextsep{0pt}
\begin{document}

\begin{abstract}
...
\end{abstract}
\maketitle
\tableofcontents

\begin{wrapfigure}{r}{6.5cm}
\begin{tikzcd}[column sep=9pt, scale cd=0.9]
    && \vdots && \vdots && \vdots \\
    \\
    0 && {A^{k+1}} && {B^{k+1}} && {C^{k+1}} && 0 \\
    \\
    0 && {A^{k}} && {B^k} && {C^{k}} && 0 \\
    \\
    0 && {A^{k-1}} && {B^{k-1}} && {C^{k-1}} && 0 \\
    \\
    && \vdots && \vdots && \vdots
    \arrow[from=5-7, to=5-9]
    \arrow["j", from=5-5, to=5-7]
    \arrow["i", from=5-3, to=5-5]
    \arrow[from=5-1, to=5-3]
    \arrow[from=7-1, to=7-3]
    \arrow["i", from=7-3, to=7-5]
    \arrow["j", from=7-5, to=7-7]
    \arrow[from=7-7, to=7-9]
    \arrow["d_A", shorten <=3pt, shorten >=3pt, from=5-3, to=3-3]
    \arrow["d_B", shorten <=3pt, shorten >=3pt, from=5-5, to=3-5]
    \arrow["d_C", shorten <=3pt, shorten >=3pt, from=5-7, to=3-7]
    \arrow["d_C", shorten <=3pt, shorten >=3pt, from=7-7, to=5-7]
    \arrow["d_B", shorten <=3pt, shorten >=3pt, from=7-5, to=5-5]
    \arrow["d_A", shorten <=3pt, shorten >=3pt, from=7-3, to=5-3]
    \arrow[from=9-3, to=7-3]
    \arrow[from=9-5, to=7-5]
    \arrow[from=9-7, to=7-7]
    \arrow[from=3-7, to=3-9]
    \arrow["j", from=3-5, to=3-7]
    \arrow["i", from=3-3, to=3-5]
    \arrow[from=3-1, to=3-3]
    \arrow[from=3-3, to=1-3]
    \arrow[from=3-5, to=1-5]
    \arrow[from=3-7, to=1-7]
\end{tikzcd}
\end{wrapfigure}
\lipsum

\end{document}

答案2

  • tikz-cd图表被重新绘制成更加简单和简短的形式。
  • 通过使用命令vdots减小图表顶部的垂直尺寸\smash
  • wrapfigure明确保留的垂直空间。
\documentclass[psamsfonts]{amsart}
\usepackage{tikz-cd}
\usepackage{wrapfig}
\usepackage{lipsum}

\title{}
\author{}
\date{}
\begin{document}

\begin{abstract}
Summary of article
\end{abstract}
\maketitle
\tableofcontents

\section{Introduction}
\begin{wrapfigure}[18]{r}{6.4cm}
    \centering
\begin{tikzcd}[column sep=2em,
               row sep=7ex,
                cells={nodes={inner xsep=2pt}},
               font=\footnotesize]
        & \vdots 
            & \vdots 
                & \vdots 
                    & ~     \\
0 \rar  & A^{k+1} \uar \rar["i"]
            & B^{k+1} \uar \rar["j"]
                & C^{k+1} \uar \rar
                    & 0     \\
0 \rar  & A^{k} \uar["d_A"] \rar["i"]
            & B^{k} \uar["d_B"] \rar["j"]
                & C^{k} \uar["d_C"] \rar
                    & 0     \\
0 \rar  & A^{k-1} \uar["d_A"] \rar["i"]
            & B^{k-1} \uar["d_B"] \rar["j"]
                & C^{k-1} \uar["d_C"] \rar
                    & 0     \\
        & \vdots \uar 
            & \vdots \uar
                & \vdots \uar 
                    &       \\
    \end{tikzcd}
\end{wrapfigure}
\lipsum[1-2]

\end{document}

在此处输入图片描述

注意:通常,您可以vrapfigure通过在序言中添加以下内容来删除额外的垂直空间

\usepackage{etoolbox}
\BeforeBeginEnvironment{wrapfigure}{\setlength\intextsep{0pt}}

但是,在这种特殊情况下,由于单元格中的位置,这似乎(在视觉上)不够\vdots,即上方是小空白区域。如果这不是问题,那么您可以使用此设置并从上方图像代码中\intextsep删除。\smash

答案3

您不需要猜测图表的宽度:让 TeX 来计算它。

我还简化了图表的编码:不需要将行数和列数加倍,也不需要计算位置:只需将箭头放在源单元格中。

\documentclass{amsart}

%\usepackage{quiver}
\usepackage{tikz-cd}
\usepackage{wrapfig}
\usepackage{lipsum}

\tikzcdset{
  scale cd/.style={
    every label/.append style={scale=#1},
    cells={nodes={scale=#1}}
  },
}
\newcommand{\svdots}{\smash{\vdots}\mathstrut}
\setlength{\intextsep}{0pt}
\newsavebox{\tikzcdbox}

\begin{document}

\begin{lrbox}{\tikzcdbox}
\begin{tikzcd}[
  scale cd=0.9,
  row sep=2.5em,
  column sep=2em,
  short/.style={shorten <=3pt, shorten >=3pt},
]
& \svdots & \svdots & \svdots \\
0 \arrow[r] &
A^{k+1} \arrow[r,"i"] \arrow[u,short] &
B^{k+1} \arrow[r,"j"] \arrow[u,short] &
C^{k+1} \arrow[r]     \arrow[u,short] &
0
\\
0 \arrow[r] &
A^{k} \arrow[r,"i"] \arrow[u,"d_A", short] &
B^{k} \arrow[r,"j"] \arrow[u,"d_B", short] &
C^{k} \arrow[r]     \arrow[u,"d_C", short] &
0
\\
0 \arrow[r] &
A^{k-1} \arrow[r,"i"] \arrow[u,"d_A", short] &
B^{k-1} \arrow[r,"j"] \arrow[u,"d_B", short] &
C^{k-1} \arrow[r]     \arrow[u,"d_C", short] &
0
\\
& \svdots \arrow[u,short] & \svdots \arrow[u,short] & \svdots \arrow[u,short]
\end{tikzcd}
\end{lrbox}
\begin{wrapfigure}{r}{\wd\tikzcdbox}
\usebox{\tikzcdbox}
\end{wrapfigure}

\lipsum

\end{document}

在此处输入图片描述

psamsfonts选项已过时,仅用于与 20 多年的旧文档兼容。

相关内容