关于子文件和 tikzpicture 的错误

关于子文件和 tikzpicture 的错误

我有一个 main.tex 和一个子文件。Subfile.tex 文件独立运行,但当我将其与 main.tex 一起运行时,软剪辑代码会出错。有什么办法可以解决这个问题吗?我哪里做错了?

我的 main.tex 是

\documentclass[10pt,twoside]{book}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{stmaryrd}
\usepackage{tasks}
\usepackage[ddmmyyyy]{datetime}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}
\usepackage{xypic}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage[turkish,shorthands=:!]{babel}
\usepackage[titles]{tocloft}
\setcounter{MaxMatrixCols}{10}

\usepackage{subfiles}


\usetikzlibrary{calc,angles,positioning,intersections,quotes, arrows, arrows.meta, 
 decorations.markings, patterns, datavisualization}
\usepgfplotslibrary{fillbetween, polar}
\pgfplotsset{compat=newest}
\usepgflibrary{shapes.geometric}

\pgfplotsset{my style/.append style={axis x line=middle, axis y line=
    middle, xlabel={$x$}, ylabel={$y$}, axis equal }}

\linespread{1.5}

\newtheorem{theorem}{Teorem}[section]
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Sonu\c{c}}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Sonu\c{c}}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Tan\i m}
\newtheorem{exercise}[theorem]{\"{O}dev}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notasyon}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{\"{O}nerme}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Kan\i t]{\noindent\text{#1:} }{$\square$}
\newenvironment{remark}[1][Not]{\noindent\textbf{#1:} }{}
\newenvironment{solution}[1][\c{C}\"{o}z\"{u}m]{\noindent\text{#1:} }{}
\newenvironment{example}[1][\"{O}rnek]{\noindent\textbf{#1:} }{}
\renewcommand{\dateseparator}{.}
\renewcommand{\cftsecfont}{\normalfont\bfseries}
\renewcommand{\cftsecpagefont}{\normalfont\bfseries}
\renewcommand{\cftdotsep}{1}




\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\fancyhead[L]{\nouppercase{\rightmark}}
\fancyhead[R]{\thepage}

\renewcommand{\subsectionmark}[1]{
\markright{{\thesubsection.\ #1}}}
\renewcommand{\headrulewidth}{0.5pt}

\let\oldsection\section% Store \section in \oldsection
\renewcommand{\section}{\cleardoublepage\oldsection}

\begin{document}
\frontmatter
\title{\textbf{TOPOLOGY}}
\author{Dr}
\date{\today }
\maketitle
\thispagestyle{empty}
\tableofcontents
\thispagestyle{empty}
\clearpage\null\thispagestyle{empty}
\renewcommand{\thesection}{\arabic{section}} \clearpage
\pagenumbering{arabic}
\mainmatter
\subfile{subfile}
\end{document}

我的 subfile.tex 是

\documentclass{article}
\usepackage{makeidx}
\usepackage{amsmath, amssymb}
\usepackage{amsfonts}
\usepackage{stmaryrd}
\usepackage{tasks}
\usepackage[ddmmyyyy]{datetime}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}
\usepackage{xypic}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usepackage{xcolor}

\setcounter{MaxMatrixCols}{10}
%TCIDATA{OutputFilter=LATEX.DLL}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{<META NAME="SaveForMode" CONTENT="1">}
%TCIDATA{BibliographyScheme=Manual}
%TCIDATA{Created=Monday, November 25, 2019 14:11:36}
%TCIDATA{LastRevised=Friday, March 04, 2022 10:39:47}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="DocumentShell" CONTENT="Standard LaTeX\Blank - Standard LaTeX Article">}
%TCIDATA{CSTFile=LaTeX article (bright).cst}

\usetikzlibrary{calc,angles,positioning,intersections,quotes, arrows, arrows.meta, 
decorations.markings, patterns, datavisualization}
\usepgfplotslibrary{fillbetween, polar}
\pgfplotsset{compat=newest}
\usepgflibrary{shapes.geometric}
\pgfplotsset{my style/.append style={axis x line=middle, axis y line=
middle, xlabel={$x$}, ylabel={$y$}, axis equal }}
\linespread{1.5}
\newtheorem{theorem}{Teorem}
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Sonu\c{c}}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Sonu\c{c}}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Tan\i m}
\newtheorem{example}[theorem]{\"{O}rnek}
\newtheorem{exercise}[theorem]{\"{O}dev}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notasyon}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{\"{O}nerme}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Kan\i t]{\noindent\text{#1:} }{$\square$}
\newenvironment{remark}[1][Not]{\noindent\textbf{#1:} }{}
\newenvironment{solution}[1][\c{C}\"{o}z\"{u}m]{\noindent\text{#1:} }{}
\renewcommand{\dateseparator}{.}


\begin{document}

\begin{tikzpicture}[scale=0.6]
        \begin{axis}[width=10cm, height=10cm, axis equal image, clip=false, xticklabel style= 
{font=,below left }, yticklabel style={font=, left}, axis lines=middle,
            xmin=-1,xmax=5,
            ymin=-2,ymax=5,
            restrict y to domain=-15:15,
            xtick={1,3},ytick= 
            {0},
            xticklabels={1,3},yticklabels= 
            {0},
            axis line style={latex-latex},
            axis line style={->},
            x label style={at={(ticklabel* cs:1)},
                anchor=west,},
            y label style={at={(ticklabel* cs:1)},
                anchor=south},
            xlabel={$x$},
            ylabel={$y$}
            ]
            \draw[name path=A, dashed, very thick] (1,-2)-- (1,4);
            \draw[name path=B, dashed, very thick] (3,-2)-- (3,4);
            \addplot[gray, opacity=0.2] fill between [of = A and B, soft clip = {domain y 
            =-2:4}];
            \node at (2,2) {$B$};
            \node [anchor=north] at (axis cs:-0.25,-.07) {$ 0$};
        \end{axis}
    \end{tikzpicture}

   \end{document}

答案1

使用子文件,可以使用其前导码独立于主文件进行编译。

他们应该从\documentclass[./main.tex]{subfiles}

参见以下示例。将接下来的三个文件放入工作目录中。

这是第一个子文件: subfile_green.tex. 先编译

% !TeX TS-program = pdflatex

%% File subfile_green.tex   
\documentclass[./main.tex]{subfiles} % changed <<<<<<<<<<<<<<<<<<<<<<<

\begin{document}
    
    \begin{tikzpicture}[scale=0.6]
        \begin{axis}[width=10cm, height=10cm, axis equal image, clip=false, xticklabel style= 
            {font=,below left }, yticklabel style={font=, left}, axis lines=middle,
            xmin=-1,xmax=5,
            ymin=-2,ymax=5,
            restrict y to domain=-15:15,
            xtick={1,3},ytick= 
            {0},
            xticklabels={1,3},yticklabels= 
            {0},
            axis line style={latex-latex},
            axis line style={->},
            x label style={at={(ticklabel* cs:1)},
                anchor=west,},
            y label style={at={(ticklabel* cs:1)},
                anchor=south},
            xlabel={$x$},
            ylabel={$y$}
            ]
            \draw[name path=A, dashed, very thick] (1,-2)-- (1,4);
            \draw[name path=B, dashed, very thick] (3,-2)-- (3,4);
            \addplot[green, opacity=0.2] fill between [of = A and B, soft clip = {domain y  =-2:4}]; % green <<<<<<<<<<<<<<<
            \node at (2,2) {$B$};
            \node [anchor=north] at (axis cs:-0.25,-.07) {$ 0$};
        \end{axis}
    \end{tikzpicture}
    
\end{document}

输出(单页)为subfile_green.pdf

G

这是第二个子文件:(subfile_red.tex仅改变了颜色}。接下来进行编译。

% !TeX TS-program = pdflatex

%% File subfile_red.tex 
\documentclass[./main.tex]{subfiles} % changed <<<<<<<<<<<<<<<<<<<<<<<

\begin{document}
    
    \begin{tikzpicture}[scale=0.6]
        \begin{axis}[width=10cm, height=10cm, axis equal image, clip=false, xticklabel style= 
            {font=,below left }, yticklabel style={font=, left}, axis lines=middle,
            xmin=-1,xmax=5,
            ymin=-2,ymax=5,
            restrict y to domain=-15:15,
            xtick={1,3},ytick= 
            {0},
            xticklabels={1,3},yticklabels= 
            {0},
            axis line style={latex-latex},
            axis line style={->},
            x label style={at={(ticklabel* cs:1)},
                anchor=west,},
            y label style={at={(ticklabel* cs:1)},
                anchor=south},
            xlabel={$x$},
            ylabel={$y$}
            ]
            \draw[name path=A, dashed, very thick] (1,-2)-- (1,4);
            \draw[name path=B, dashed, very thick] (3,-2)-- (3,4);
            \addplot[red, opacity=0.2] fill between [of = A and B, soft clip = {domain y =-2:4}]; % red <<<<<<<<<<<<<<<<
            \node at (2,2) {$B$};
            \node [anchor=north] at (axis cs:-0.25,-.07) {$ 0$};
        \end{axis}
    \end{tikzpicture}
    
\end{document}

输出(单页)为subfile_red.pdf

r

最后编译main.tex包含两个子文件。

% !TeX TS-program = pdflatex

% File main.tex

\documentclass[10pt,twoside]{book}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{stmaryrd}
\usepackage{tasks}
\usepackage[ddmmyyyy]{datetime}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
%\usepackage{tikz}
\usepackage{xypic}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage[turkish,shorthands=:!]{babel}
\usepackage[titles]{tocloft}
\setcounter{MaxMatrixCols}{10}

\usepackage{subfiles}

\usetikzlibrary{calc,angles,positioning,intersections,quotes, arrows, arrows.meta, 
    decorations.markings, patterns, datavisualization}
\usepgfplotslibrary{fillbetween, polar}
\pgfplotsset{compat=newest}
\usepgflibrary{shapes.geometric}

\pgfplotsset{my style/.append style={axis x line=middle, axis y line=
        middle, xlabel={$x$}, ylabel={$y$}, axis equal }}

\linespread{1.5}

\newtheorem{theorem}{Teorem}[section]
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Sonu\c{c}}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Sonu\c{c}}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Tan\i m}
\newtheorem{exercise}[theorem]{\"{O}dev}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notasyon}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{\"{O}nerme}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Kan\i t]{\noindent\text{#1:} }{$\square$}
\newenvironment{remark}[1][Not]{\noindent\textbf{#1:} }{}
\newenvironment{solution}[1][\c{C}\"{o}z\"{u}m]{\noindent\text{#1:} }{}
\newenvironment{example}[1][\"{O}rnek]{\noindent\textbf{#1:} }{}
\renewcommand{\dateseparator}{.}
\renewcommand{\cftsecfont}{\normalfont\bfseries}
\renewcommand{\cftsecpagefont}{\normalfont\bfseries}
\renewcommand{\cftdotsep}{1}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\fancyhead[L]{\nouppercase{\rightmark}}
\fancyhead[R]{\thepage}

\renewcommand{\subsectionmark}[1]{
    \markright{{\thesubsection.\ #1}}}
\renewcommand{\headrulewidth}{0.5pt}

\let\oldsection\section% Store \section in \oldsection
\renewcommand{\section}{\cleardoublepage\oldsection}

\begin{document}
    \frontmatter
    \title{\textbf{TOPOLOGY}}
    \author{Dr}
    \date{\today }
    \maketitle
    \thispagestyle{empty}
    \tableofcontents
    \thispagestyle{empty}
    \clearpage\null\thispagestyle{empty}
    \renewcommand{\thesection}{\arabic{section}} \clearpage
    \pagenumbering{arabic}
    \mainmatter
    
    \subfile{subfile_green} % first subfile <<<<<<<<<<<<
    
    \subfile{subfile_red} % second subfile <<<<<<<<<<<
    
\end{document}

编译后的结果是(加上标题页)

在此处输入图片描述

相关内容