You have empty lines between the document
and tikzpicture
environment which puts the picture in an paragraph (which is \textwidth
wide). Simply removing the lines fixes this:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [step=0.5] (-1.4,-1.4) grid (1.4,1.4);
\end{tikzpicture}
\end{document}
The rest of your question is already answered in
Compile a LaTeX document into a PNG image that's as short as possible.
In short:
pdflatex file
convert -density 300 file.pdf -quality 90 file.png
or with v1.0 of the standalone
class:
\documentclass[convert={density=300,size=1080x800,outext=.png}]{standalone}
compile with:
pdflatex -shell-escape file
You might also want to use the new border
option to set the border to 0pt
.
\draw (20,12) -- ++(2,0) -- ++(0,2) -- ++(-3,0) -- ++(45:3);
Use ++
before each new incremental coordinate to make it relative to the last one and put the pencil there.
Here's a complete example:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz\draw (20,12) -- ++(2,0) -- ++(0,2) -- ++(-3,0) -- ++(30:3) {[rounded corners=10pt]-- ++(5,0) -- ++(0,-6)} -- ++(-7,0) -- cycle;
\end{document}
Of course, combining this with the -| or |- path operators can simplify the code even further; the following two pieces of code produce the same result:
\tikz\draw (20,12) -- ++(2,0) -- ++(0,2) -- ++(3,0) -- ++(0,1) -- ++(1,0) -- ++(0,-3) -- ++(2,0);\par\bigskip
and
\tikz\draw (20,12) -| ++(2,2) -| ++(3,1) -- ++(1,0) |- ++(2,-3);
I don't think that defining commands in this case adds anything; in fact, I think it reduces the functionality of the existing syntax (which is already simple). The example demonstrates that you can use, for example, polar coordinates and modify (up to TikZ limitations) the path attributes midways; even if the current question doesn't require this, it's a good thing to have the possibility to do those kind of modification if they are required.
Best Answer
TikZ (or rather
pgf
) resets some aspects of the drawing state at the start of atikzpicture
. This includes the colour and line width, but not the line-joining approach. PDFs do not 'reset' these values automatically when included inside other PDFs, and so the 'child' PDF inherits whatever is set in the 'parent'. As such, if you change the line-joining setting, this will show up in any included PDF that does not explicitly set it. The same would be true for colour or line width in the abstract, but the TikZ reset means that effectively the 'child' is insulated from any change in the 'parent'.This general point was discussed in https://github.com/pgf-tikz/pgf/issues/870. One could apply
to force appropriate defaults.