You want
\VerbatimInput{text/1985.txt}
not
\VerbatimInput{\input{text/1985.txt}}
to avoid inputting the file .tex
There are two problems:
- if you say
code={...}
, ...
has to be some code, not something like key=blabla
. You can define keys by using e.g. \tikzset
, though.
- If you have
n args=2
, the two arguments have to be passed to the pic
via \pic {withscope={3}{8}};
and not \pic {withscope={3,8}};
Taking this into account, the MWE becomes
\documentclass{article}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.16} %
\usetikzlibrary{positioning}
\begin{document}
\tikzset{
pics/withscope/.style n args={2}{
code = { %scale=#1,
%mypathstyle/.style={line width=#2mm, ->},
\begin{scope}
[scale=#1,
%mypathstyle/.style would only work here if path inside scope
every node/.append style={transform shape},
nodestyle/.style={circle,draw=black,fill=white,thick, font=\bfseries}]
%nodes
\node(1) [nodestyle] {$1$};
\node(2) [right=of 1] [nodestyle] {$2$};
\end{scope}
} %code
}, % style
pics/withscope/.default={1}{2}
} %tikzset
\tikzset{
pics/thisisscopeless/.style n args={1}{
code = { %
\tikzset{mypathstyle/.style={line width=#1mm, ->},
every node/.append style={transform shape},}
%nodestyle/.style wont work
\node(1) [circle,draw=black,fill=white,thick, font=\bfseries] {$1$};
\node(2) [right=of 1] [circle,draw=black,fill=white,thick, font=\bfseries] {$2$};
} %code
}, % style
pics/thisisscopeless/.default={1}
} %tikzset
Loading without parameter works\\[2cm]
\begin{tikzpicture}
\pic {withscope};
\end{tikzpicture}
putting everything in tikzpicture works
\begin{tikzpicture} [scale=1.5,
every node/.append style={transform shape},
nodestyle/.style={circle,draw=black,fill=white,thick, font=\bfseries},
mypathstyle/.style={line width=0.2mm, ->}]
\node(1) [nodestyle] {$1$};
\node(2) [right=of 1] [nodestyle] {$2$};
%path
\draw [mypathstyle] (1) -- (2) node[pos=0.5,above] {2};
\end{tikzpicture}
scale doesn't work with scope \textbf{because the options are local}
\begin{tikzpicture}[scale=2,mypathstyle/.style={line width=0.5mm, ->}]
\pic {withscope};
% %path
\draw [mypathstyle] (1) -- (2) node[pos=0.5,above] {3};
\end{tikzpicture}
without scope it works
\begin{tikzpicture}[scale=2,
every node/.append style={transform shape},
mypathstyle/.style={line width=0.5mm, ->}]
\pic {thisisscopeless};
\draw [mypathstyle] (1) -- (2) node[pos=0.5,above] {4};
\end{tikzpicture}
with scope the scale in tkzpicture won't work. You can hand scale through
tikzset, but this isnt great.
\begin{tikzpicture}[scale=3,mypathstyle/.style={line width=0.5mm, ->}]
\pic {withscope={3}{8}}; %corrected syntax for two arguments
% %path
\draw [mypathstyle] (1) -- (2) node[pos=0.5,above] {5};
\end{tikzpicture}
without mypathstyle in tikzpicture gives an error as "mypathstyle" is unknown\\
\begin{tikzpicture}%[mypathstyle/.style={line width=0.5mm, ->}]
\pic {withscope={4}{8}};%corrected syntax for two arguments
% %path
%\draw [mypathstyle] (1) -- (2) node[pos=0.5,above] {6};
% doesn't work because mypathstyle is defined in scope
\end{tikzpicture}
\end{document}
Best Answer
Here is a solution that adresses both of your issues:
Here is how I address your issues:
Vertical alignment: I defined a common point (named
(base)
at(0,-.5em)
) in both of your TikZ picture. And I defined it as the reference for the baseline (cf. the global optionbaseline=(base)]%
for eachtikzpicture
). It means this particular point will be vertically aligned with your text baseline.Horizontal blankspace: In your macro definition, the first line ends with space character (
). It means that if you wrap lines 1 and 2, your code will look like this:
\newcommand{\dashedTri}{ \begin{tikzpicture}
; i.e. your embedding a space in your macro definition that is added on top of the space befor your command in your.tex
document.(Note that I changed in your code
\node[very thick, mark size=3pt,color=black] at (1mm,0){
into\node[very thick, mark size=3pt,color=black] at (2.5mm,0){
(i.e.1mm
into2.5mm
) so that theplotmark
is horizontally aligned regarding the dashed line.)