我想要 xshift 一整块 tikz 图纸并进行以下设置:
%
% Document.
%
\documentclass[10pt,halfline,a4paper]{index}
%
% Packages.
%
\usepackage[numbers]{natbib}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage{mathrsfs}
\usepackage{multicol}
\usepackage{tikz}
\usepackage{tikz-cd}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{wasysym}
\usepackage{etoolbox}
\usepackage{bm}
\usepackage[hidelinks]{hyperref}
\usetikzlibrary{patterns}
%
% Document start.
%
\begin{document}
%
% Header.
%
\title{Demo}
%
% Abstract.
%
\abstract{Demo. \cite{foo}}
\maketitle
%
% Introduction.
%
\section{Introduction}
Hello
\begin{tikzpicture}[scale=1]
\demoscopedcircle{5}{xshift=3cm}
\end{tikzpicture}
World
%
% Conclusion.
%
\section{Conclusion}
%
% References.
%
\bibliographystyle{plainnat}
\bibliography{./index}
%
% Appendix.
%
\appendix
\end{document}
使用类文件:
%
% Set latex version.
%
\NeedsTeXFormat{LaTeX2e}[2018/03/16 Demo Latex]
%
% Expose `index`.
%
\ProvidesClass{./index}
%
% Configure.
%
\DeclareOption{oneline}{\PassOptionsToPackage{doublespacing}{setspace}}
\DeclareOption{halfline}{\PassOptionsToPackage{onehalfspacing}{setspace}}
\DeclareOption{endnotes}{\ProvidesPackage{endnotes}\note@endtrue}
\DeclareOption{numbib}{\num@bibtrue}
\DeclareOption{nonumbib}{\num@bibfalse}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
%
% Import packages.
%
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage{amsfonts}
\RequirePackage{verbatim}
\RequirePackage{graphicx}
\RequirePackage{setspace}
\RequirePackage{endnotes}
\RequirePackage[left=.7in,right=.7in,top=1in,bottom=1in]{geometry}
\RequirePackage{xspace}
\RequirePackage{amscd}
\RequirePackage{rotating}
\RequirePackage{latexsym}
\RequirePackage{multicol}
\RequirePackage{array}
\RequirePackage{algorithm}
\RequirePackage{subfigure}
\RequirePackage[hyphens,obeyspaces]{url}
\newcommand\demosquare[1]{\tikz{\filldraw[draw=#1,fill=#1] (0,0) rectangle (0.2cm, 0.2cm);}}
\newcommand\demotriangle[1]{\tikz{\filldraw[draw=#1,fill=#1] (0,0) -- (0.2cm,0) -- (0.1cm,0.2cm);}}
\newcommand\democircle[1]{\tikz{\filldraw[draw=#1,fill=#1] (0,0) circle [radius=0.1cm];}}
\newcommand\demoscopedcircle[2][]{
\begin{scope}[#1]
\democircle{red}
\end{scope}
}
\newcommand\demovspace[1]{
\foreach \i in {1,...,#1} {
\hfill \break
}
}
%
% Define `abstract`.
%
\let \@abstract \relax
\long \gdef \abstract#1{{%
\gdef \@abstract{%
\small%
\begin{center}{%
\bfseries \abstractname\vspace{-.5em}\vspace{\z@}%
}\end{center}%
{\quotation%
\noindent#1%
\endquotation}%
\par%
}}}
%
% Define `author`.
%
\def \author#1 {%
\def \and{\\}%
\gdef \@author{#1}%
}
%
% Make title.
%
\def \@maketitle {%
\newpage
\null
\vskip 2em%
{\leftskip\z@ plus 1fill\rightskip\leftskip
\let \footnote \thanks
{\LARGE \noindent\@title \par}%
\vskip 1em%
{\large \noindent\@date}%
\vskip 2em%
\@abstract%
\vskip0em
\par}
\vskip 1.5em}
关键内容如下:
\newcommand\demoscopedcircle[2][]{
\begin{scope}[#1]
\democircle{red}
\end{scope}
}
和
Hello
\begin{tikzpicture}[scale=1]
\demoscopedcircle{5}{xshift=10cm}
\end{tikzpicture}
World
我只是想xshift
移动圆圈,并让它从宏外部进行配置\demoscopedcircle
。
答案1
您的范围已经转移,但您看不到它,除非您将其他东西放入其中tikzpicture
与转移的内容进行比较(即使是透明的东西也足够了)。
\documentclass{article}
\usepackage{tikz}
\newcommand{\democircle}[1]{\filldraw[#1] circle [radius=0.1cm];}
\newcommand{\demoscopedcircle}[2][]{
\begin{scope}[#1]
\democircle{#2}
\end{scope}
}
\begin{document}
Hello
\begin{tikzpicture}[scale=1]
\demoscopedcircle[xshift=10cm]{red}
\end{tikzpicture}
World
Hello
\begin{tikzpicture}[scale=1]
\fill circle (1pt) ;
\demoscopedcircle[xshift=10cm]{red}
\end{tikzpicture}
World
Hello
\begin{tikzpicture}[scale=1]
\fill[opacity=0] circle (1pt) ;
\demoscopedcircle[xshift=10cm]{red}
\end{tikzpicture}
World
\end{document}