Tag Info

27

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

23

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

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 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, }] ...

20

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

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

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 ...

15

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

12

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

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 ...

11

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); ...

9

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); ...

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

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{% ...

7

Not exactly what you are looking for (no subgrid) but coordinates are shown. \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{decorations.pathreplacing} \makeatletter \def\tikz@Get@x@coor#1,#2\tikz@sentinel{% \pgfmathparse{int(round(#1/1cm))}} \def\tikz@Get@y@coor#1,#2\tikz@sentinel{% \pgfmathparse{int(round(#2/1cm))}} \tikzset{% show ...

7

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 ...

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

7

The grid function stumbles because the y vector is negative. If you draw the grid from the bottom up by specifying a ystep=-0.1, it works fine: \documentclass{article} \usepackage{tikz} \usetikzlibrary{matrix} \usepackage{adjustbox} \begin{document} \begin{tikzpicture}[xscale=1,yscale=1,auto, inner sep=0pt,remember picture] \node[anchor=north west,inner ...

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

I'm not sure I understood correctly the question. I forgot to add name at each cell. Update \documentclass{article} \usepackage{tikz} \usetikzlibrary{shapes} \begin{document} \begin{tikzpicture} [hexa/.style= {shape=regular polygon,regular polygon sides=6,minimum size=1cm, draw,inner sep=0,anchor=south,fill=lightgray!85!blue,rotate=30}] \foreach \j in ...

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 ...

6

A proof of concept; the idea is to use pgfplotstable; the first table is typeset, appropriately reserving space for the values of the second table; then, the second table is typeset and superimposed to the first one, using a simple \llap: \documentclass{article} \usepackage{pgfplotstable} ...

6

I am sorry but there's no easy solution. First I tried using a to path but that doesn't let you change the line style:-( Next I tried implementing a dedicated command. This time the main problem is that in order to iterate over the coordinate labels, the labels should be integral, which isn't true in general. The following should work, but it requires ...

6

As an example of how you could implement my comment. You could consider the following code. \documentclass{article} \usepackage{tikz} \usetikzlibrary{matrix,calc} \def\tminus{\node[minimum height=1.33cm]{\tikz\draw plot[smooth cycle, tension=0.25] coordinates{(-.5cm,-.5ex) (.5cm,-.5ex) (.5cm,.5ex) (-.5cm,.5ex)};};} \def\tplus{\node[minimum height=1.33cm] ...

5

The problem is the combination between the chosen shader=flat and opacity: deactivate opacity and you do not see any edges. Internally, the shader draws surface segments "on top of each other". It simply paints them (with fill and stroke). But since adjacent surface segments share edges, these edges are used twice for the opacity computation, resulting in ...

5

An idea but there is a problem with size like 3 cm. This modified version is easier but I always a problem with grids like 3*3 \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{tikz} \begin{document} \begin{tikzpicture}[mygrid/.style={draw,minimum height=#1,minimum width=#1, path ...

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