3

I would like to xshift a whole block of tikz drawings and have this setup:

%
% 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}

With class file:

%
% 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}

The key lines are:

\newcommand\demoscopedcircle[2][]{
  \begin{scope}[#1]
    \democircle{red}
  \end{scope}
}

and

Hello
\begin{tikzpicture}[scale=1]
  \demoscopedcircle{5}{xshift=10cm}
\end{tikzpicture}
World

I would just like the xshift to move the circle, and have it be configurable from the outside on the \demoscopedcircle macro.

  • Your \demoscopedcircle takes one optional argument and one required argument. The optional argument has an empty value. The required argument is never used. \demoscopedcircle[xshift=10cm]{} is going to do what you want (except that the second argument is useless). – TH. Mar 17 '18 at 4:48
  • Using a minimal working example (MWE) that illustrates your problem would help. You included a lot of unnecessary code. – TH. Mar 17 '18 at 4:51
  • Sorry, I am still working on getting a minimal working example up and running, I started from a bulky project. Thank you for your kindness. – Lance Pollard Mar 17 '18 at 4:58
2

Your scope is shifted, but you can't see it unless you put something else in the tikzpicture to compare from what it is shifted off (even a transparent thing is enought).

enter image description here

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.