Tag Info

Hot answers tagged tikz-pgf

19

EDIT: changed \ifthenelse to \ifnum as suggested by percusse and Heiko. \documentclass[tikz,border=2mm]{standalone} \begin{document} \begin{tikzpicture} \foreach \n in {0,...,6} { \foreach \k in {0,...,\n} { \node (\n\k) at (\k,-\n) {${\n \choose \k}$}; \pgfmathtruncatemacro{\x}{(\n+1)/2} ...

11

I advise for an external solution, too. But surely, it is possible in TeX. It just takes a bit of time. As this is a recursive solution, it might take more time than a non-recursive, but the recursive one is relative easy to implement. If one defines cantor 2 edge/.style={move to} the diagonal part will not be drawn. (It's not an edge in an TikZ path ...

7

Here is a first attempt with MetaPost, with a number of iterations n to be chosen at will, 10 on this example. It surely needs refinement, but it shows anyway it can be done with it. To be typeset with LuaLaTeX. Edit A second, recursive implementation, much more refined. vardef cantor(expr A, B, n) = if n = 0 : A -- B else: save C, D; pair C, ...

7

I'd love to see someone do this directly in LaTeX, but in the meantime, it's probably easiest to generate the data using some other method and plot the resulting data file. Here's a Python script that uses the cantor function from http://stackoverflow.com/a/17810389/1456857 to generate the data file: def cantor(n): return [0.] + cant(0., 1., n) + [1.] ...

7

I don't think it's necessary to use pgfplots. I think you can get the effect you want (and somewhat easier) using just tikz. \documentclass[border=5pt]{standalone} \usepackage{tikz} \usetikzlibrary{calc} \usetikzlibrary{arrows.meta} \begin{document} \begin{tikzpicture} \coordinate (Q) at (0,0); %% put this first even though you can use opacity. ...

7

Here's a suggestion using a decoration to mark points along the curves and then loop through joining them up. I'm using TikZ-level commands for the decoration which jars slightly with the low-level PGF commands that you're using; but I don't know the low-level equivalents off the top of my head. It works because decorations step along paths according to ...

6

For this sort of semi-technical sketch you might consider Metapost as an alternative tool. Here I've followed my preferred sequence to keep everything nicely organized: define the paths (relative to each other as far as possible); draw them; then add the labels. prologues := 3; outputtemplate := "%j%c.eps"; beginfig(1); % set a unit scale u := 1cm; % ...

6

There is a trick that can be used in some circumstances which exploits the fact that a pic is put inside a scope which can be named with the local bounding box key. Note that this will not work in trees or graphs. \documentclass[tikz,border=5]{standalone} \tikzset{pics/.cd, pic a/.style={code={ \node [fill=red!20, shape=circle] {A}; }} } ...

6

A sagetex solution using the (free) SageMathCloud for access to the computer algebra system Sage rather than installing Sage locally on your computer. There's probably a simpler and better way to implement it; I'm not known for my programming skills. I get up to 9 iterations of construction; Sage is literally plotting a line segment at the appropriate ...

6

\documentclass{article} \usepackage{cancel,mathtools,stackengine} \stackMath \def\CBN#1#2{% \cancel{\addstackgap[6pt]{\kern6pt\displaystyle\binom{#1}{#2}\kern6pt}}% } \def\BN#1#2{% \addstackgap[6pt]{\kern6pt\displaystyle\binom{#1}{#2}\kern6pt}% } \begin{document} \[ \def\stackalignment{l} \setstackgap{S}{-5.2pt} \setstackEOL{\cr} \Shortstack{ ...

6

This isn't precisely what the OP requests, I think, but it's similar... \documentclass{book} \usepackage{mathtools} \usepackage{cancel} \begin{document} \LARGE \boldmath % horizontal loop \foreach \x in {0,...,6} {% % vertical loop \foreach \y in {0,...,\x} {% $\cancel{\binom{\x}{\y}}$ } } \end{document}

5

Something like that? Done with MetaPost, inserted in a LuaLaTeX program. \documentclass[border=2mm]{standalone} \usepackage{luamplib} \begin{document} \begin{mplibcode} vardef Sierpinski_var(expr A, B, C, n) = % The recursive macro filldraw A -- B -- C -- cycle; % Current triangle if n>0: save AC, BC, AB; pair AC[], BC[], AB[]; AC1 = ...

5

For first, you can use a decoration like this. First define one \usetikzlibrary{decorations.markings,arrows.meta,bending} \tikzset{ myarrows/.style ={ postaction=decorate, decoration={ markings, mark={between positions 0.001 and 1 step 0.25 with \arrow{Latex[reversed,fill=none,flex]}} } }, } Then use a \foreach loop like ...

5

Here's a more dynamic approach in which you do not have to write out each of the vertices' names. \documentclass{article} \usepackage{etoolbox} \usepackage{tkz-berge} \def\myInstance#1#2{$#1_{#2}$} \newcommand\aeAssignLabels[3]{%% \let\myexecutable\relax \foreach \myn in {#3} {%% \ifx\myexecutable\relax ...

5

Here's a simple solution with Tikz. You could do it with plots but I think it's easier to do it this way. The "plot" curve is a simple edge drawn with the command \draw (-4.5,-3) edge[out=0,in=180,looseness=1.5] (4.5,3);. As you can see the starting and the ending point are symmetrical. The control options inside of edge specify where the edge comes out (0 ...

5

edge is a beast so you should ride on it carefully. Use -> in the option of edge not \draw: \documentclass[border=10pt]{standalone} \usepackage{tikz} \usetikzlibrary{arrows,positioning,shapes.geometric} \begin{document} \begin{tikzpicture}[>=latex'] \tikzset{block/.style= {draw,rectangle,align=center,minimum width=2cm,minimum height=1cm}} ...

4

This thread is quite old and there is an update. First: compiling the plot in question with pdflatex has the accuracy difficulties for this challenging function and the other answers are valid. However, the version 1.12 of pgfplots comes with a lua backend which uses lua's advanced math functions. Compiling the example in question with lualatex results in ...

4

Solution 1 as asked in the first version of the OP: I leave the fine tuning to you. Just adapt the height and width of the ellipses and set \begin{tikzcd}[column sep=xxx, row sep=xxx]... as you please. If you want to change the arrow heads, you will do some search on this site here. Plenty of help is given all over the place. % arara: pdflatex ...

4

In a nutshell, if you pass more than a file name (a path) to pgfdeclareimage, pdflatex looks just there. Otherwise, it looks for it in the complete search path, which traditionally is specified in the TEXINPUTS environment variable. So a simple solution would be to add ./art to TEXINPUTS and then just use the file name in pdfdeclareimage. However, as this ...

4

I slightly changed your \foreach statement to include [evaluate=\x as \degree using int(\x*30)] and $\degree^\circ$ to print degrees. You can change the steps by changing the number 30. Output Code \documentclass[margin=10pt]{standalone} \usepackage{amsmath,amsfonts,amsthm} \usepackage{gensymb} \usepackage{tikz} \begin{document} \begin{tikzpicture} ...

4

Dependently on the complexity of your use-cases and how many of these shapes you need … here is a start. The answer consists the following: A shape declaration that borrows the rectangle ee definition from the circuits.ee (which is just a borrowed rectangle shape with .input and .output anchors). I also borrow from the linked TeXample for the text ...

4

May be like this. \documentclass{amsart} \usepackage{tikz} \usetikzlibrary{calc,intersections,quotes,backgrounds} \begin{document} \begin{tikzpicture} \coordinate (A) at (-0.5,-0.75); \coordinate (B) at (-0.5,0.5); \coordinate (C) at (1,0.5); \coordinate (D) at (1,-0.75); \path[fill=yellow] (A) -- (B) -- (C) -- (D) -- cycle; \path[draw,name path=ray1] ...

4

An Asymptote MWE: // Cantor.asy settings.tex="pdflatex"; import graph; real w=8cm,h=w; size(w,h); import fontsize;defaultpen(fontsize(9pt)); texpreamble("\usepackage{lmodern}"); xaxis(0,1,RightTicks(Step=0.20,step=0.1)); yaxis(0,1,LeftTicks (Step=0.20,step=0.1)); real eps=1e-10; real fn (real x,int n){ real u; if(n>0){ if(0 <=x ...

4

When I searched for a package to do this, I didn't find anything which did not require some kind of hack. At the time, I hacked qtree. Now, I would probably use forest: \documentclass[tikz,border=5pt]{standalone} \usepackage{forest} \begin{document} \forestset{ ass/.append style={ before computing xy={l=\baselineskip}, no edge }, } ...

3

Change your \drawme as \newcommand{\drawme}[3]{ \draw[*->,rounded corners=10pt] ($(#1 north)!0.5!(#1 south)$) -- ++(0,#3) -| (#2); } I have changed |- ++(0,#3) to -- ++(0,#3) Code: \documentclass{article} \usepackage[pdftex,active,tightpage]{preview} \setlength\PreviewBorder{2mm} \usepackage{xifthen} \usepackage{tikz} ...

3

The problem is that latex is converting the & before tikz can parse it. See example on page 1048. \documentclass{article} \usepackage{tikz} \newcommand{\SES}[3]{% \begin{center} \begin{tikzpicture}[every node/.style={midway}] \let\&=\pgfmatrixnextcell \matrix[column sep={2em}, row sep={0em}] at (0,0) { \node(A) {$0$} ; \& \node(B) {#1} ...

3

Something like this? Mine is different, I think, from Harish Kumar's so I will post even though he answered first. Note that with my method, the second intersection point is the one you want, so I named the first one Q just so the second would be P. \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{calc,intersections,quotes,backgrounds} ...

3

You can plot in 3-D coordinates. This should get you started: Note that the order that you draw the different parts of the diagram is important: I have drawn the shaded section first so that it is "behind" the other lines. \documentclass[border=5mm,tikz]{standalone} \usepackage{mwe} \usepackage{tikz} \begin{document} \begin{tikzpicture}[every ...

3

You can use \pgfmathparse to multiply. Since you get the decimals, you may need int also like node[anchor = north] {\pgfmathparse{int(30*\x)}$\SI{\pgfmathresult}{\degree}$}; Note that I have used siunitx for the degrees. \documentclass{article} \usepackage{tikz} \usepackage{siunitx} \begin{document} \begin{tikzpicture} \draw[step = 0.5 cm, gray, very ...

3

You can say [right=<dimension> of <coordinate>] rather than just using [right] at (<coordinate>). For example, \node [above left=12mm and 15mm of A] {P}; will create the node with a P in it 12mm above and 15mm to the left of A. So, you might move P and Q something like this: \documentclass[tikz,border=5pt]{standalone} ...

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