Tag Info

Hot answers tagged

30

Here's a quick option: \begin{tikzpicture} \foreach \i in {0,...,3} \foreach \j in {0,...,3} { \foreach \a in {0,120,-120} \draw (3*\i,2*sin{60}*\j) -- +(\a:1); \foreach \a in {0,120,-120} \draw (3*\i+3*cos{60},2*sin{60}*\j+sin{60}) -- +(\a:1);} \end{tikzpicture} Which results in


24

With TikZ, you can define a pattern which allows to fill any shape with a hexagonal grid by adding the option pattern=hexagons: \documentclass{article} \usepackage{tikz} \usetikzlibrary{patterns} \def\hexagonsize{0.5cm} \pgfdeclarepatternformonly {hexagons}% name {\pgfpointorigin}% lower left {\pgfpoint{3*\hexagonsize}{0.866025*2*\hexagonsize}}% ...


23

A funny solution (have you ever used lindenmayersystems library?): \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{lindenmayersystems} \begin{document} \begin{tikzpicture} \pgfdeclarelindenmayersystem{triangular grid}{\rule{F->F-F+++F--F}} \path[draw=black, l-system={triangular grid,step=1cm, angle=-60,axiom=F--F--F,order=4, }] ...


22

If you make the coordinates not an exact multiple of the step size you can get this effect: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[step=0.5cm,color=gray] (.75,.75) grid (3.75,3.75); \end{tikzpicture} \end{document}


21

A try in pgfplots in case you ever decide to learn/use it. :-) In this case, much of the code is setting up the styling to match your example. This could be stored as a style defined once in your document, as I have done, and used for consistent style for all plots. There is surely a better way to draw the double line at the outer edge. I tried lots of ...


21

Like Leo said: use \foreach and some math: \usetikzlibrary{calc} \newcommand*\rows{10} \begin{tikzpicture} \foreach \row in {0, 1, ...,\rows} { \draw ($\row*(0.5, {0.5*sqrt(3)})$) -- ($(\rows,0)+\row*(-0.5, {0.5*sqrt(3)})$); \draw ($\row*(1, 0)$) -- ($(\rows/2,{\rows/2*sqrt(3)})+\row*(0.5,{-0.5*sqrt(3)})$); \draw ($\row*(1, 0)$) ...


20

A very basic approach using grid: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw (0,0) grid (3,3); \draw (0,4) grid (3,7); \draw (4,0) grid (7,3); \draw (4,4) grid (7,7); \foreach \i/\valor in {1/1,2/2,3/3,5/n-2,6/n-1,7/n} { \node[anchor=south] at (\i-0.5,7) {$\valor$}; \node[anchor=east] at (0,-\i+7.5) ...


18

Here's a solution that uses to paths to execute arbitrary code in the guise of a simple command. If the preamble were hidden away in a package, the invocation would just be: \begin{tikzpicture} \draw (-2,-2) to[grid with coordinates] (7,4); \end{tikzpicture} The sneaky trick is to use the fact that the to path declaration can contain arbitrary code via a ...


18

As with most of the settings in pgfplots, you can set these things globally in the preamble using \pgfplotsset For example minor ticks: \pgfplotsset{minor grid style={dashed,red}} major ticks: \pgfplotsset{major grid style={dotted,green!50!black}} both minor and major ticks: \pgfplotsset{grid style={dashed,gray}} A complete MWE follows ...


18

You could use PGFplots (version 1.5) for this. It can draw polar axes with very flexible customisation possibilities: \documentclass{article} \usepackage{pgfplots} \usepgfplotslibrary{polar} \begin{document} \begin{tikzpicture} \begin{polaraxis}[ width=40cm, xmin=160,xmax=200, ymin=2,ymax=3, yticklabels={}, xtick={160,165,...,200}, ...


17

Version 1.5 of pgfplots includes a Smith chart library. This is an example from its manual \documentclass{standalone} \usepackage{pgfplots} \usepgfplotslibrary{smithchart} \begin{document} \begin{tikzpicture}[scale=0.75] \begin{smithchart}[ title=Huge Smith Chart (rescaled), width=20cm] \addplot coordinates {(0.5,0.2) (1,0.8) (2,2)}; \end{smithchart} ...


17

Okay, here’s what I came up with. It isn’t in the “spirit” of the question, since I haven’t used any of TikZ’s polar coordinate features: instead, I just drew the grid on by hand and with some basic loops. This is the code I used, with some hopefully self-explanatory comments: \documentclass{article} \usepackage{tikz} \begin{document} ...


13

In the pgfmanual it says on p. 145 that due to rounding errors, the "last" lines of a grid may be omitted. In this case, you have to add an epsilon to the corner points In this case, you will have to subtract an epsilon, i.e. a very small value, from the corner point. Something like \draw[step=0.5cm,color=gray] (2-0.001,2-0.001) grid (4,4); ...


12

TikZ doesn't have a node shape of this form. But since it is just a rectangle with some added lines, it is relatively straightforward to define (once knowing how to define shapes). \documentclass{article} \usepackage{tikz} \usetikzlibrary{positioning} \makeatletter \pgfkeys{/pgf/grid lines/.initial=2} \pgfdeclareshape{grid}{ % inherit most things from ...


10

If you care for something a bit fancier, you could also try that one: \documentclass{article} \usepackage{tikz} \usetikzlibrary{fadings} \begin{document} \begin{tikzpicture} \draw[step=0.5cm,color=gray,path fading=south] (.99,.75) grid (3.5,1); \draw[step=0.5cm,color=gray,path fading=north] (.99,3.5) grid (3.5,3.75); ...


10

A slightly different solution using a matrix transformation and clipping: \newcommand*{\rows}{10} \pgfmathsetmacro{\xcoord}{cos(60)} \pgfmathsetmacro{\ycoord}{sin(60)} \begin{tikzpicture} \pgftransformcm{1}{0}{\xcoord}{\ycoord}{\pgfpointorigin} \path[clip,preaction = {draw=black}] (\rows,0) -- (0,0) -- (0,\rows) -- cycle; \draw (0,0) grid ...


9

The eso-pic package lets you add material to each page. With TikZ you can draw a nice background grid. \documentclass{article} \usepackage{tikz} \usepackage{eso-pic} \AddToShipoutPicture{% \begin{tikzpicture}[overlay,remember picture] \draw[thick,red] (current page.north east) rectangle (current page.south west); ...


9

Late to the party but another opportunity of nonlinear transformations and pretty printing radians for me. I stole the plotted function from alexwlchan's answer. \documentclass[tikz]{standalone} \usetikzlibrary{fpu} \usepgfmodule{nonlineartransformations} \makeatletter ...


9

Not exactly an answer because I think it's more complicated to transform a tool than to create a new tool. Like Andrew says it's impossible in your case. Here a macro : ( I made this code in few minutes also I think tikz's expert can do a better macro with more options) \documentclass{article} \usepackage{fullpage,tikz} \makeatletter \pgfkeys{% ...


8

EDIT : This issue is now fixed in the current development version (CVS) of TikZ/PGF. The fix is not what is proposed below but from Till Tantau's comment: Fixed in CVS. However, negative increments are (still) not allowed. Instead, the two parameters of the pgfpathgrid command are now considered as two corners of a rectangle rather than as ...


8

This can be easily done with TikZ: \documentclass{article} \usepackage{tikz} \begin{document} Simple grid: \medskip \tikz\draw [thin] (0,0) grid (5,5); More complex grid: \medskip \begin{tikzpicture} \draw [thin, step=0.1, gray] (0,0) grid (5,5); \draw [thick, gray] (0,0) grid (5,5); \end{tikzpicture} \end{document}


8

With PSTricks, the following is too short for typing exercise. \documentclass[border=12pt,pstricks]{standalone} \usepackage{pst-plot} \def\r{2*(1-sin(x))} \begin{document} \begin{pspicture}[algebraic,plotpoints=100,polarplot](-5.5,-5.5)(5.5,5.5) \psaxes[axesstyle=polar,subticklinestyle=dashed](5,0) ...


8

Not hard to do in Metapost... prologues := 3; outputtemplate := "%j%c.eps"; beginfig(1); s = 1cm; path f; f = (for t = 0 upto 359: (cosd(t), sind(t)) scaled (2-2sind(t)) .. endfor cycle) scaled s; fill subpath(0,90) of f -- subpath(270,360) of f .. cycle withcolor .1 red + .7 white; for r = s/2 step s until 4s: draw fullcircle scaled 2r withcolor .8 ...


8

Yes, it can be done in TikZ. I enclose my try. %! *latex mal-polar.tex \documentclass[a4paper]{article} \pagestyle{empty} \usepackage{tikz} \begin{document} \begin{tikzpicture}[>=latex] \fill[fill=lightgray] plot[domain=-pi/2:pi/2] (xy polar cs:angle=\x r,radius= {2-2*sin(\x r)}); \draw[thick, color=red, domain=0:2*pi, samples=200,smooth] plot (xy polar ...


7

As described in How to define a figure size so that it consumes the rest of a page?, first define a measure to measure the remaining space on the page \definemeasure[page][\dimexpr\pagegoal-\pagetotal-\lineheight\relax] Then use a frame with its height equal to this measure \framed[height=\measure{page}, width=\textwidth]{} Now, to add a grid, you can ...


7

Some corrections are necessary (you're forgetting \topskip) \newbox\gridbox \setbox\gridbox\line{% \special{color push rgb .8 .8 1}% \vrule height\baselineskip width0pt \hrulefill \special{color pop}} \def\grid{\vtop to0pt{\hrule height0pt\kern-\dimexpr\baselineskip-\topskip\relax \vbox to\dimexpr\vsize+2pt\relax{\leaders\copy\gridbox\vfil}\vss}} ...


7

Lualatex solution: \begin{tikzpicture} \directlua{grid = readGridFile("example.dat"); plot(grid)} \end{tikzpicture} \end{document} Now the whole document. Note that I used package filecontents to include in a single source all the required files to typeset the example. You can safely remove those filecontents* environments after the first ...


7

To get a minor grid you need minor ticks. You can enable those with e.g. minor tick num=2 which adds two minor ticks between each major tick. \documentclass[11pt]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[grid=both,xlabel={error},ylabel={power},minor tick num=2] ...


7

The venerable graphpap package does not provide a command to do that, but it's not hard to write your own command that does what you want. \documentclass[a4paper]{article} \usepackage{graphpap} \makeatletter \newcommand\graphpapern[1][10]{\leavevmode\@gridn{#1}} \def\@gridn#1(#2,#3)#4{\@grid@n{#1}{#2}{#3}(} \def\@grid@n#1#2#3(#4,#5){% \@tempcnta=#4\relax ...


7

This should do what you want. A box consisting of the requested number of lines, drawn at the baselines, is added with \AtBeginShipout. \documentclass{article} \usepackage{atbegshi,picture,xcolor} \AtBeginShipout{% \AtBeginShipoutUpperLeft{% \color{red}% \put(\dimexpr 1in+\oddsidemargin, -\dimexpr ...



Only top voted, non community-wiki answers of a minimum length are eligible