2

I am writing a latex document and while writing a commutative diagram using the tikz environment, the width of the compiled diagram is beyond the width of the rest of the text. Here's the code:

\documentclass[12pt,a4paper]{report}
\makeatletter
% these two slashes-commands for continuous chapter numbering in parts of the document
\makeatother
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\huge}{\thechapter.}{20pt}{\huge\bf} %for chapter headings
\RequirePackage{etoolbox}
\usepackage{tikz-cd} % and in the above line to use commutative diagrams
\usepackage{amsfonts}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}
% below four lines to just one or two cyrillic letter
\DeclareFontFamily{U}{wncy}{}
\DeclareFontShape{U}{wncy}{m}{n}{<->wncyr10}{}
\DeclareSymbolFont{mcy}{U}{wncy}{m}{n}
\DeclareMathSymbol{\Sh}{\mathord}{mcy}{"58} 
 %Cyrillic letter command over
\usepackage{sagetex}
\usepackage[toc]{appendix} % to make appendi appear in the table of contents
 \usepackage{amssymb}  %to use direct sum symbol
 \usepackage{graphicx} %toinsert images
 \usepackage{amsmath} %to use matrices
 \usepackage{hyperref}
 \usepackage{bm} % to use bold font in math mode use \bm{ insert math mode text}
 \usepackage{mathrsfs} %for scripted english characters
 \usepackage{mathtools}
 \usepackage{tikz-cd} % to draw commutative diagrams
 \usepackage{enumitem}

All this can be combined in the following:
\[
\begin{tikzcd}
  0 \arrow{r} & 
\frac{E'(K)}{\phi(E(K))} \arrow{r}{\delta} \arrow{d} &
H^{1}(G_K, E[\phi]) \arrow{r} \arrow{d}{Res_v} &
WC(E/K)[\phi] \arrow{r} \arrow{d} & 0 \\
0 \arrow{r} &
\frac{E'(K_v)}{\phi(E(K_v))} \arrow{r}{\delta_{v}} \arrow{d} &
H^{1}(G_{v}, E[\phi]) \arrow{r} \arrow{d} & 
WC(E/K_{v})[\phi] \arrow{r} \arrow{d} & 0 \\
0 \arrow{r} & 
\prod\limits_{v \in M_K} \frac{E'(K_v)}{\phi(E(K_v))} \arrow{r}{\prod\limits_{v \in M_K}\delta_{v}} &
\prod\limits_{v \in M_K} H^{1}(G_{v}, E[\phi]) \arrow{r} &
\prod\limits_{v \in M_K} WC(E/K_{v})[\phi] \arrow{r} & 0 
\tag{$**$} 
\label{starstar}
\end{tikzcd}  
\]
\end{document}

It would be great if someone could help me in this. Thank you so much.

1 Answer 1

3

To fit your diagram in text width you should take two measured:

  • reduce distance between nodes
  • use smaller font
  • use \mathclap from the mathtools package for writing limits of products:
\documentclass[12pt,a4paper]{report}
\usepackage{mathtools}
\usepackage{tikz-cd}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{equation}\label{starstar}
    \begin{tikzcd}[sep=1.8em, font=\small]
0 \ar{r} & \frac{E'(K)}{\phi(E(K))} \ar{r}{\delta} \ar{d} 
    & H^{1}(G_K, E[\phi]) \ar{r} \ar{d}{Res_v} & WC(E/K)[\phi] \ar{r} \ar{d} & 0 \\
0 \ar{r} & \frac{E'(K_v)}{\phi(E(K_v))} \ar{r}{\delta_{v}} \ar{d} 
    & H^{1}(G_{v}, E[\phi]) \ar{r} \ar{d} & WC(E/K_{v})[\phi] \ar{r} \ar{d} & 0 \\
0 \ar{r} & \prod\limits_{\mathclap{v \in M_K}} \frac{E'(K_v)}{\phi(E(K_v))} 
            \ar{r}{\prod\limits_{\mathclap{v \in M_K}}\delta_{v}} 
    &
\prod\limits_{\mathclap{v \in M_K}} H^{1}(G_{v}, E[\phi]) \ar{r} &
\prod\limits_{\mathclap{v \in M_K}} WC(E/K_{v})[\phi] \ar{r} & 0
\end{tikzcd}  
\tag{$**$}
    \end{equation}   
\end{document}

enter image description here

5
  • I am getting the following error: Package pgfkeys error on using the above code. More details: ! Package pgfkeys Error: I do not know the key '/tikz/sep' and I am going to ig nore it. Perhaps you misspelled it. See the pgfkeys package documentation for explanation. Type H <return> for immediate help.
    – Shreya
    Apr 18, 2020 at 4:18
  • I removed 'sep=1.8em' from your code and the rest of the it is working perfectly, the only difference is that the tag $**$ is right below the diagram instead of on the right side to it. But that's not a big problem. Thank you again!
    – Shreya
    Apr 18, 2020 at 4:34
  • 1
    @Shreya, I select sep=1.8em that tag (**) can be inline with diagram. MWE is tested with recent MIkTeX installation. If you use Overleaf then can happen that there are older version of packages which doesn't work as expected. Try to use column sep instead of sep.
    – Zarko
    Apr 18, 2020 at 4:41
  • I am using a really old installation of TeXmaker with TexLive. And what you suggested is still not working though. I appreciate the help though. Thanks~
    – Shreya
    Apr 18, 2020 at 4:47
  • 1
    @Shreya, try to update your LaTeX installation. As far as I read in site, now is available version TexLive 2020.
    – Zarko
    Apr 18, 2020 at 4:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .