Quantcast
Channel: Question and Answer » tikz-pgf
Viewing all 959 articles
Browse latest View live

How to place a background image on page (using tikz?) that goes behind everything

$
0
0

I want to place an image behind everything on a specific page in my document to liven it up a bit. The first I tried to do was to do was put in a tikz-picture as background, and it worked pretty well, but infortunately the header gets drawn over.

Here is the essential code I have used so far, and its output:

documentclass[11pt,a4paper,twoside]{scrbook}
RequirePackage{microtype}
RequirePackage{pdfpages}

usepackage{lipsum}
usepackage{lettrine}
usepackage{tikz}
usepackage{multicol}

% Dimensions:
setlengthtopmargin{-58pt}                 
setlengthheadheight{20pt}                 
setlengthheadsep{25pt}                 
setlengthmarginparwidth{-20pt}            
setlengthtextwidth{paperwidth - 82pt}    
setlengthtextheight{paperheight - 112pt} 
setlengthoddsidemargin{-30pt}
setlengthevensidemargin{-30pt}

% Header and Footer:
usepackage{fancyhdr}
% Header
lhead[thepage]{Edition}
rhead[Name]{thepage}
chead{sffamily HEADER}
% Headercolour
renewcommand{headrulewidth}{1pt}% 2pt header rule
renewcommand{headrule}{hbox toheadwidth{%
color{black}leadershrule height headrulewidthhfill}}
% Footer
lfoot{}
rfoot{}
cfoot{vspace{-20pt}textcolor{black}{rule{textwidth}{1pt}}}

% Fonts:
usepackage{mathptmx}   % Serif
usepackage{DejaVuSans} % Sans-serif
usepackage[T1]{fontenc}
usepackage{xstring}

begin{document}

noindent
begin{tikzpicture}[remember picture,overlay]
node (background) at (0.5textwidth,-0.5textheight+15pt) {includegraphics[height=paperheight+20pt]{bak}};
draw [white , fill=white, opacity=0.7](-15pt,-topmargin+5pt) rectangle (textwidth+10pt,-topmargin-headheight-10pt);
draw [white , fill=white, opacity=0.7](-15pt,15pt) rectangle (textwidth+10pt,-textheight);
draw [white , fill=white, opacity=0.7](-15pt,-textheight-22pt) rectangle (textwidth+10pt,-textheight-30pt);
end{tikzpicture}
pagestyle{fancy}

begin{multicols}{2}
lettrine[loversize=0.1]{A}{S} I said, this is a test. lipsum
end{multicols}
clearpage

begin{multicols}{2}
lipsum
end{multicols}

end{document}

The output

Notice that of the two pages, only the second has a header. In the other the tikz-picture has drawn on top of it. If there is some way to make tikz draw underneath the header, or even to force a re-draw of the header, that would solve my problems. But I do not know how to do any of these.

Notice also that the footer does show up, whereas the header disappears behind the tikz drawing, for some reason. I don’t know what to make of this.

Any ideas?


Recreating diffraction image with TikZ

$
0
0

I’d like to recreate the image below of an electron beam passing through — and being diffracted by — a carbon target onto a curved screen using TikZ. Unfortunately it looks a bit beyond my skill level. How could I recreate this?

enter image description here

Custom Shape with tcolorbox/tikz

$
0
0

I’m trying to make a custom rectangle to surround my section headers. It’s a regular rectangle with the upper-left and lower-right corners “cut” so they’re diagonal.

I want it to look like this: pic

I tried to modify the long example from tcolorbox pages 201–202, but am only getting missing corners.

Here’s my MWE:

documentclass[13pt]{extarticle}
usepackage[paperwidth=9in, paperheight=6in, margin=0.3in, marginparwidth=0.6in]{geometry}
usepackage[usenames,dvipsnames]{xcolor}
usepackage{tikz}
usepackage{tcolorbox}
tcbuselibrary{skins,breakable}
pagestyle{empty}
begin{document}
tcbset{nobeforeafter, colbacktitle=white, colback=white, coltitle=black, width=.5linewidth}

begin{tcolorbox}[enhanced, frame code={path[tcb fill frame] (frame.south west)--([yshift=-5mm]frame.north west)
--([xshift=5mm]frame.north west)--(frame.north east)--([yshift=-5mm]frame.north east)
--([yshift=5mm]frame.south east)--([xshift=-5mm]frame.south east)--cycle;}]
Sample Text
end{tcolorbox}
end{document}

But it’s looking like this: error picture

Can anyone help me figure out why it’s not drawing correctly? Or should I be using something else and not tcolorbox?

How to get rid of white space when drawing lines in TikZ with documentclass=standalone?

$
0
0

I get an annoying white space in my rendered graphics with lines that begin or end at the page’s borders. I am using the “standalone” document class for actually not having those margins.

Let us assume the following code for my TikZ graphic.

documentclass[tikz]{standalone}

usepackage{tikz}
usepackage{color}

begin{document}

    begin{tikzpicture}
        %   simple gray box
        fill[darkgray] (0, 0) rectangle (2, 2);
        %   green line beginning from the left
        draw[green, line width=0.5cm] (0, 1) -- (1, 1);
    end{tikzpicture}

end{document}

What I get with the above TeX code is this image (zoomed in for better seeing what I mean):

unwanted white space on the left

By dragging that image around with your mouse you sure will mention that there is some white space between the image’s left border and the gray box (where the image should actually begin).

And yes, I know that this white space would totally make sense if I had drawn the line like this:

draw[green, line width=0.5cm] (0, 1.5) -- (0, 1) -- (1, 1);

…But I didn’t.

In my case I only need to draw horizontal lines from left to right and not along the border. I also use dark boxes in the background like the gray one in the example above. So, that white space is really bothering me.

How can I get rid of that?

vertical lines in matrix using tikz package

$
0
0

my problem is interconnected to my two previous posts (here and here) and i’ve tried to incorporate answers into solution but without success.

My task is this matrix multiplication with added description:
My task

and my so far code follows:

documentclass{article}
usepackage{tikz,amsmath} 
begin{document}
begin{tikzpicture}
node[minimum height=0cm,minimum width=2cm] (m) {};
path[shade,draw] (0,2) -- (0,5) -- (3,5) -- (3,0);
draw (0,0) --(0,5);
draw (3,0) --(0,2);
draw (3,0) --(3,5);
node (r11) at ([xshift=0.6cm,yshift=4cm]m.south) {$S_{11}$};
node (r11) at ([xshift=2.5cm,yshift=4cm]m.south) {$S_{12}$};
node (r11) at ([xshift=2.5cm,yshift=2.15cm]m.south) {$S_{22}$};
node (r11) at ([xshift=0.6cm,yshift=2.15cm]m.south) {$S_{21}$};
node (r11) at ([xshift=0.6cm,yshift=2.6cm]m.south) {$--------------$};
node (r11) at ([xshift=0.6cm,yshift=1.5cm]m.south) {$--------------$};
end{tikzpicture}
[
begin{bmatrix}
begin{equation}
       wn_{1}           \[0.3em]
       wn_{2}    

 end{bmatrix}
 ]
 end{document}    

with following output:

My Output

I am not able to add vertical line and nodes and incorporate the matrix into document (vector that follows behind the matrix is not centered). Problem with nodes and incorporation is the same as in this question.

Is there a way to systematically ignore specific error messages?

$
0
0

When I compile my documents with a lot of trees, I often get the following error code:

! Dimension too large.
<recently read> pgf@xa 

l.1042 }}

This error is due to some temporary computation that tikz does (I use forest) and goes away after the next compilation of the document. So I would like to have some switch that turns such messages into warnings. Is this possible?

Declaring sinc in tikz

$
0
0

I am trying to declare the sinc-function for usage in tikz. I tried two different ways:

documentclass{standalone}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
begin{tikzpicture}
    tikzmath{
        function sincm(x) {
            if abs(x) < 0.001 then {
                return 1.0;
            } else {
                return sin(x r)/x;
            };
        };
    }
    pgfmathdeclarefunction{sinc}{1}{%
        pgfmathparse{%
            abs(#1)<0.001 ? 1 : sin(#1 r)/#1%
            }%
        }

    draw (-1,0) -- (1,0);
    draw[domain=0:0.5, samples=1000] plot (x, {sincm(x*20)});
    draw[domain=0:0.5, samples=1000, red, dotted] plot (x,{sinc(x*20)});

end{tikzpicture}
end{document}

Both ways yield the same result. I would like to use pgfmathdeclarefunction variante, first of all to be able to declare this function globally, maybe even for several tikz-pictures. However, if I set the start of the plotting domain to zero:

draw[domain=0:0.5, samples=1000, red, dotted] plot (x,{sinc(x*20)});

I get the Error Package PGF Math Error: You've asked me to divide '0,0' by '0.0'. Somehow, in this case, the ifthenelse-structure in my declaration of sinc does not seem to work?

Drawing an activation stack in LaTeX

$
0
0

I am trying to draw an activation stack. I am really bat at TikZ, so I hope you can help me out.

Activation Stack Diagram

As you can see, there are four boxes stacked one on top of the other. Each box has a name, put on the right, and is made of an upper part, where variables and numbers are displayed, and a lower part which is divided in two halves. The left half has to contain an arrow pointing to one of the boxes placed under it, the right half contains only a few characters. The box at the bottom hdoesn’t have a pointy arrow, because it doesn’t have to reference anything.

I really hope you can help me out, I really appreciate it.


How to label nodes in a Hasse diagram?

$
0
0

In this question I’m using the term label in the traditional sense of word. I clarify this because I’m under the impression that this is also a technical term within the TeX universe.

The code

documentclass{article}

 usepackage{tikz}

  begin{document}
   begin{center}
    begin{tikzpicture}

      node (u) at (0,0) {$circ$};
      node [below left  of=u] (e)  {$circ$};
      node [below right of=u] (f) {$circ$};
      node [below right of =e] (d) {$circ$};

      draw [black, shorten <=-7pt, shorten >=-6.6pt] (u) -- (e);
      draw [black, shorten <=-7pt, shorten >=-6.6pt] (u) -- (f);
      draw [black, shorten <=-7pt, shorten >=-6.6pt] (e) -- (d);
      draw [black, shorten <=-7pt, shorten >=-6.6pt] (f) -- (d);

    end{tikzpicture}
   end{center}
  end{document}

yields

hasse diagram

How can I label the nodes in the following fashion?

Labeled hasse diagram

Fading line with same color at both the ends

$
0
0

I wanted a fading line with the same color at both the ends and a second color in the middle. Here is the crude MWE I came up with:

documentclass{article}
usepackage{tikz}                                                                       
begin{document}
  begin{tikzpicture}[baseline]
    path[left color=white,right color=black]
    (0,0) rectangle (.5textwidth,.5pt);%
    path[left color=black,right color=white]
    (.5textwidth,0) rectangle (textwidth,.5pt); 
  end{tikzpicture}
end{document}

This leaves a tiny tiny gap in the center. (Or is it just an optical illusion I get because I know I have used two path commands?)

Is there a better way of doing it? May be, with only one path/ fill/ rectangle command?

Ending a tikzpicture environment in conditional causes “Missing } inserted”

$
0
0

I want to create a number of tikzpictures. I have a number of items I want to draw. Each tikzpicture takes up a whole page and may contain up to 4 items. (It is not good enough to to have each item in its own tikzpicture.) So if there are 16 items, I will need 4 tikzpictures, but if there are 17 I will need 5. I thought I could loop over the items in the list using a counter and begin and end tikzpictures at the appropriate points (and end any open tikzpicture at the end if the last one is not full up). But it doesn’t work. If I hit the end{tikzpicture} at the end of the loop then I get Missing } inserted. I anticipate this has something to do with TeX groups, but I do not know how to work with environments in a way that gets around groups.

Here is a minimal example.

documentclass{minimal}

usepackage{tikz}

newcounter{mycounter}

defiteration{%
    stepcounter{mycounter}%
    ifnum5=value{mycounter}%
        setcounter{mycounter}{1}%
        begin{tikzpicture}%
    fi%
    draw (0, 0) -- (1, 0);%
    ifnum4=value{mycounter}%
        end{tikzpicture}%
    fi%
}

begin{document}%
    setcounter{mycounter}{4}%
    foreach x in {1, 2, 3, 4, 5, 6} {iteration}%
    ifnum4>value{mycounter}%
        end{tikzpicture}%
    fi%
end{document}

Tikz relative positioning with ++

$
0
0

The red rectangle is in the correct position, but I need the blue ones to be 4 and 8mm to the right of the red on the same height (not below, as my code makes it).

What is wrong with my use of ++?

documentclass{beamer}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{frame}[fragile]
frametitle{Tikztezt}
begin{figure}flushleft

begin{tikzpicture}
tikzset{bar1mm/.style={shape=rectangle, fill=blue, minimum height=5mm, minimum width=1mm, anchor=west}}
node[bar1mm, fill=red] at (10mm,10mm) {}
++(4mm,0mm) node[bar1mm] {}
++(4mm,0mm) node[bar1mm] {};
end{tikzpicture}

end{figure}
end{frame}
end{document}

I actually need to position a lot of nodes, and the code here is just a minimum workable example, which is why I prefer ++.

how to remove the background for png picture

$
0
0

I would like to make the background transparent. In Texmaker, if I right-click on the TikZ picture, I can save it as a png image as follows

enter image description here

If I save this picture, I get the white background. Is there a way to remove it?

documentclass[border=10pt,tikz]{standalone}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{calc,fit,arrows.meta, positioning}
usepackage{graphicx}
usetikzlibrary{calc}

begin{document}

begin{tikzpicture}[auto,node distance=3cm,>={Stealth[width=4mm, length=6mm, fill=red]}]
coordinate (O) at (5,0);


draw [very thick,fill=green,fill opacity=.2] 
(-4, 4) circle (2.0cm) node [fill opacity=1]{textbf{A}};

end{tikzpicture}

end{document}

Filling the intersection area of two circles and ellipse

$
0
0

I found a picture like this.

enter image description here

I want to fill the intersection area of two circles and ellipse.
This is what I have done:

documentclass{article}
usepackage{geometry}
usepackage{tikz}
begin{document}
centering
begin{tikzpicture}[scale=2]
coordinate (P) at (0,0) ;
coordinate (Q) at (5,0) ;
coordinate (R) at (5,4) ;
coordinate (S) at (0,4) ;
draw[] (P)--(Q)--(R)--(S)--cycle;
draw[fill=gray] (2,2) circle (1.5cm);
draw[fill=white] (2.75,2) circle (0.75cm);
draw[fill=gray] plot [smooth cycle] coordinates {(3.1,2) (3.24,1.75) (3.46,1.67) (3.5,2) (3.46,2.33) (3.24,2.25) };
draw[] plot [smooth cycle] coordinates {(3.46,1.67) (3.77,1.73) (3.94,2) (3.77,2.27) (3.46,2.33) (3.5,2) (3.46,1.67)};
end{tikzpicture}
end{document}

I feel the result is not so good, for the ellipse. How to improve it?

pgfgantt – adjust vgrid with gantttitlecalendar

$
0
0

I am using gantttitlecalendar to generate my title block that consists of months and weeks.

The default behaviour of vgrid is to take each unit as a day, or if compress calendar is true, each unit is taken as a month.

I would like to have vertical grid lines to demarcate each week.

This is what I currently have

 % Minimal
documentclass{article}
usepackage{pgfgantt}

begin{document}

ganttset{calendar week text= small {startday/startmonth}}

begin{ganttchart}[
    hgrid,x unit=1.5mm,
    hgrid style/.style={draw=black!5, line width=.75pt},
    vgrid,
gantttitlecalendar{ month=shortname,week=4} \
ganttgroup{Group A}{22-09-14}{28-11-14}\
ganttbar{Task A}{22-09-14}{10-11-14}
end{ganttchart}

end{document}

Which gives me
Minimal example - vgird = days

How would one adjust the vgrid for weeks?


Draw between shapes in Tikz

$
0
0

I’m trying to draw lines from the center circle (General Assembly) to the Economic and Social Council and International Criminal Court circles such that the angle of incidence for the line on all three circles is 0 degrees, i.e., the line is at a 90 degree angle to the surface of the circle. Right now, this is what I have.

documentclass{article}
usetikzlibrary{calc}
usetikzlibrary{matrix, shapes}
usepackage{tikz}
usepackage{pgfplots}
usetikzlibrary{snakes}
usetikzlibrary{positioning, intersections}
pgfplotsset{compat=1.10}
begin{document}

    begin{figure}[H]
    label{fig:structure}
    centering
    begin{tikzpicture}
    node[xshift=6cm,draw,regular polygon, regular polygon sides=4,text width=3cm,align=center] (sa)
      {{Large Specialized agencies}:\
      textbullet FAO\
      textbullet ILO\
      textbullet ITU\
      textbullet WHO};
      node[minimum size= 4.5cm, xshift=12cm,draw,circle, text width=3cm,align=center] (ga) {Large{General Assembly}\
      small{1 nation, 1 vote}};
      node[xshift=12cm,yshift=-5cm,draw, circle, text width=3cm,align=center] (sc) {Large Security Council\
      small{5 permanent members\
      10 rotating members chosen by GA}};
        node[xshift=12cm,yshift=5cm,draw,circle, text width=3cm,align=center] (sg) {Large Secretary General\
      small{Supports GA decisions}};
          node[xshift=17cm,yshift=2cm,draw,circle, text width=3cm,align=center] (ecsoc) {Large Economic and Social Council
    };
          node[xshift=17cm,yshift=-2cm,draw,circle, text width=3cm,align=center] (icc) {Large International Criminal Court
    };
    draw (sa.east) -- (ga.west);
    draw (sg.south) -- (ga.north);
    draw (sc.north) -- (ga.south);
    draw (ga.east) -- (ecsoc.west);
    draw (ga.east) -- (icc.west);
    end{tikzpicture}
    caption{Structure of the United Nations}
    end{figure}

end{document}

chart

Adjust placement of commas and periods in TikZ txt style

$
0
0

In the example below, one can see that a comma and a period following a word on the baseline in a TikZ environment is based on how far the node above the word stretches towards the right. How can I change this so that the comma and the period don’t care about the node above the word, but only by the word itself?

documentclass{article}
usepackage{tikz}
newlength{Aheight}
setlength{Aheight}{fontcharhtfont`A}

newcommand{phraselabel}[2]{%
    begin{tikzpicture}[%
        baseline = (word.base),
        txt/.style = {inner sep = 0pt, text height = Aheight, draw},
        above/.style = {inner sep = 0pt, text depth = 0pt, draw}%
        ]
    node[txt] (word) {#1};
    node[above] at (word.north) {footnotesize{#2}};
    end{tikzpicture}%
    }

begin{document}
phraselabel{bb}{xxxxx}, phraselabel{bb}{xxxxx}.
end{document}

enter image description here

In TikZ, adjust the placement of a node above text

$
0
0

In the example below, I’ve managed to align the words on the baseline and the nodes above them correctly by setting text height = Aheight for the words (i.e. let the height of all words be equal to the character A) and text depth = 0pt for the nodes (i.e. let the center of all nodes be the same). What I don’t know how to do is to adjust the vertical space between the words and the nodes above. I want to raise the nodes above to a more appropriate place.

documentclass{article}
usepackage{tikz}
newlength{Aheight}
setlength{Aheight}{fontcharhtfont`A}

newcommand{phraselabel}[2]{%
    begin{tikzpicture}[%
        baseline = (word.base),
        txt/.style = {inner sep = 0pt, text height = Aheight, draw},
        above/.style = {inner sep = 0pt, text depth = 0pt, draw}%
        ]
    node[txt] (word) {#1};
    node[above] at (word.north) {footnotesize{#2}};
    end{tikzpicture}%
    }

begin{document}
phraselabel{gg}{xxxxx} phraselabel{aa}{jjjjj} phraselabel{tt}{xxxxx} phraselabel{bb}{xxxxx}.
end{document}

enter image description here

Adding words centered above other words with TikZ v2 [closed]

$
0
0

EDIT: Please vote to close this question as “Unclear what you’re asking”. My problem and my understanding of it have developed in such a way that this question is now too messy. I have opened the new questions In TikZ, adjust the placement of a node above text and Adjust placement of commas and periods in TikZ txt style.

————————————

This is a follow-up to the question I asked in
Adding words centered above other words with TikZ. I’ve tried to implement Jason’s suggestion, but I’ve found that it has spawned enough follow-up questions that it’s best to simply address them in a separate question here.

(EDIT: It’s now best to skip down to the edit at the bottom of this question.)

A MWE with output below:

documentclass{article}
usepackage{tikz}
    usetikzlibrary{calc}
newlength{Aheight}
setlength{Aheight}{fontcharhtfont`A}

newcommand{inline}[2]{%
    begin{tikzpicture}[baseline=(word.base), txt/.style={shape=rectangle, inner sep=0pt}]
    node[txt] (word) {#1};
    node[above] at (word.north) {footnotesize{#2}};
    end{tikzpicture}%
    }
newcommand{phraselabel}[2]{%
    begin{tikzpicture}[baseline=(word.base), txt/.style={shape=rectangle, inner sep=0pt}, text height = Aheight, text depth = 0pt]
    node[txt] (word) {#1};
    node[above] at (word.north) (label) {footnotesize{#2}};
        pgfkeysgetvalue{/pgf/inner xsep}{myxsep}
        pgfresetboundingbox
        useasboundingbox ($(label.south west) + (myxsep,0)$) rectangle (label.north east);
    end{tikzpicture}%
    }

begin{document}
begin{enumerate}
item inline{gg}{xx} inline{aa}{jj} inline{tt}{xx} inline{bb}{jj}.
item phraselabel{gg}{xx} phraselabel{aa}{jj} phraselabel{tt}{xx} phraselabel{bb}{jj}.
item gg aa tt bb.
item phraselabel{gg}{xxxxx} phraselabel{aa}{jjjjj} phraselabel{tt}{xxxxx} phraselabel{bb}{jjjjj}.
end{enumerate}
end{document}

enter image description here

The new command inline is Jason’s suggestion, and the new command phraselabel is my attempt to tweak it towards what I want.

First problem: In 1., we see that the label is not affected by descenders of the word below, something Jason did by setting baseline = (word.base) (xx is horizontally aligned with jj over the first two words). But 1. also shows that the labels are strongly affected by themselves having descenders (compare xx with jj over the first two words), and by the words below having ascenders (the xx over tt is lower than the jj over bb, since t has a shorter ascender than b).

I’ve fixed this problem in 2. by setting text depth = 0pt (cf. this answer) and text height to the height of the font’s A character, which is normally the tallest text character a font has (cf. Wikipedia and this answer). But now I have a worry. Aren’t I setting this up so that both the words below and the labels above have text boxes with the height of A? Clearly I have no need to set the height of the text boxes for the labels above to A. I only need to do this for the words below so that the labels above don’t collide with words that have ascending characters like A. Is there a better way to do this? Also, I’ve used the height of A because it is the highest character I know of. But what if I want the labels even higher – how do I accomplish that? Presumably by tweaking the node[above] setting?

Second problem: In 1., the sentence is pushed away from the left margin. I’ve fixed this in 2. with code from this answer. It fixes that problem, but I think it gets entangled with the third problem.

Third problem: In 1., despite the code inner sep = 0pt, there’s a lot of extra space between the words. This is improved in 2. because the extra space on the left side of the labels has been removed by changing the bounding box. Not only is there still too much space between the words, as seen when comparing with 3., but I am pretty sure that this is not the correct way to tweak the space between the words. If, for instance, I remove the extra space on the right side of the labels with useasboundingbox ($(label.south west) + (myxsep,0)$) rectangle ($(label.north east) - (myxsep,0)$);, then the words are mushed together. How can I set the space here correctly? Note, however, that extra space between the words should emerge if the labels are so wide that they risk colliding with other lables (cf. 4.).

Fourth problem: In both 1. and 2., the final period . is, as a result of the problem just noted above, being pushed away from the last word. This is even clearer in 4. where the labels are wider. How can I make the label above the last word (and a label that would be above a word followed by a comma) not care about the final period? Note that it wouldn’t be a proper solution to simply include the period into the word, as phraselabel{bb.}{jj}, because the label jj would then be centered with respect to bb. and not bb. The alignment would therefore be off.

If this all means that there are simply too many problems with this approach, and that another approach altogether would be better, I’m open to suggestions. I think it’s best to stick with TikZ, however, since I will include things like curly braces and arrows later.

—————————————————–

EDIT

I’ve made some headway now, partly driven by suddenly understanding that I might understand better what’s going on by adding boxes around the words and labels with draw.

MWE:

documentclass{article}
usepackage{tikz}
newlength{Aheight}
setlength{Aheight}{fontcharhtfont`A}

newcommand{phraselabel}[2]{%
    begin{tikzpicture}[baseline = (word.base), txt/.style = {shape = rectangle, inner sep = 0pt, text height = Aheight, draw}, above/.style = {inner sep = 0pt, text depth = 0pt, draw}]
    node[txt] (word) {#1};
    node[above] at (word.north) (label) {footnotesize{#2}};
    end{tikzpicture}%
    }

begin{document}
begin{enumerate}
item phraselabel{gg}{xx} phraselabel{aa}{jj} phraselabel{tt}{xx} phraselabel{bb}{jj}.
item gg aa tt bb.
item phraselabel{gg}{xxxxx} phraselabel{aa}{jjjjj} phraselabel{tt}{xxxxx} phraselabel{bb}{xxxxx}.
end{enumerate}
end{document}

The main fix here is that I’ve specified two separate styles txt/.style and above/.style, and specified them in appropriate ways (e.g. adding inner sep = 0pt to above/.style). The output is now this:
enter image description here

The boxes let me see that the interword spaces in 1. are now correct. It matches regular spaces. There are now two things I need to achieve:

  1. How do I adjust the vertical placement of the nodes above the words?
  2. The placement of a final period (cf. 4.) is not based on the word on the baseline, but on whichever element (baseline word or node above) is further into the margin. How can I make it only care about the baseline word?

Unobedient diagrams and a way to resume caption enumeration

$
0
0

The code at the bottom of this question yields this image. Zooming this image at a relevant place shows the following.

zoom

As you can see the last three diagrams are broken (in (vi) and (vii) 2 is lower than what I want it to be and (viii) was supposed to be the vertices of a cube). I’ve tried creating the diagrams by explicit coordinates, but it results in the same thing, it won’t work.

Another problem with this is that this is part of a larger document and the diagrams get moved to a different page due to, I assume, lack of space. I suppose this happens because the diagrams are all within begin{figure} end{figure}, but I need them to be so in order to get the appropriate caption.

How can I solve both these problems?

documentclass{article}
usepackage{tikz}
usepackage{subcaption}
renewcommandthesubfigure{roman{subfigure})}
DeclareCaptionLabelFormat{paren}{(#2}
captionsetup[subfigure]{labelformat=paren}
usetikzlibrary{positioning}
tikzset{mynode/.style={draw,circle,inner sep=2pt,outer sep=0pt}}

begin{document}
 begin{figure}[htb]
  centering
  subcaptionbox{}{%
   begin{tikzpicture}

    node [mynode,label=above:30] (30) at (0,0) {};
    node [mynode,below left  = of 30,label=left:2] (2)  {};
    node [mynode,below right = of 30,label=right:5] (5) {};
    node [mynode, below = of 30, label=right:3] (3) {};
    node [mynode,below  = of 3,label=below:1] (1) {};

    draw (30) -- (2) 
          (30) -- (5)
          (30) -- (3) 
           (2) -- (1)
           (3) -- (1) 
           (5) -- (1);

   end{tikzpicture}
  }
  hfil
  subcaptionbox{}{%
   begin{tikzpicture}

    node [mynode,label=above:12] (12) at (0,0) {};
    node [mynode,below left  = of 12,label=left:4] (4)  {};
    node [mynode,below right = of 30,label=right:3] (3) {};
    node [mynode,below left  = of 4,label=left:2] (2)  {};
    node [below = of 12] (a) {};
    node[below = of a] (b) {};
    node[mynode, below of = b, label=right:1] (1) {};

    draw (12) -- (4)
          (12) -- (3)
           (4) -- (2)
           (2) -- (1)
           (3) -- (1);

   end{tikzpicture}
  }

  subcaptionbox{}{
   begin{tikzpicture}

    node [mynode,label=above:10] (10) at (0,0) {};
    node [mynode,below left  = of 10,label=left:2] (2)  {};
    node [mynode,below right = of 10,label=right:5] (5) {};
    node [mynode,below right  = of 2,label=below:1] (1)  {};

    draw (10) -- (2)
          (10) -- (5)
           (5) -- (1)
           (2) -- (1);                   
   end{tikzpicture}
  }
  hfil
  subcaptionbox{}{
   begin{tikzpicture}                   
    node [mynode,label=right:16] (16) at (0,0) {};
    node [mynode, below of = 16, label=right:8] (8) {};
    node [mynode, below of = 8, label=right:4](4) {};
    node [mynode, below of = 4, label=right:2] (2){};
    node [mynode, below of =2, label=right:1](1){};

    draw (16) -- (8)
           (8) -- (4)
           (4) -- (2)
           (2) -- (1);                   
   end{tikzpicture}
  }

  subcaptionbox{}{
   begin{tikzpicture}                   
    node [mynode,label=right:18] (18) at (0,0) {};
    node [mynode, left of = 18, label=left:12] (12) {};
    node [mynode, below of = 18, label=right:3](3) {};
    node [mynode, below of = 12, label=left:2] (2){};

    draw (18) -- (2)
          (18) -- (3)
          (12) -- (2)
          (12) -- (3);                   
    end{tikzpicture}
  }
  hfil
  subcaptionbox{}{
   begin{tikzpicture}

    node [mynode,label=above:12] (12) at (0,0) {};
    node [mynode,below left  = of 12,label=left:4] (4)  {};
    node [below of = 12] (a) {};
    node [mynode,below right = of 12,label=right:6] (6) {};
    node [mynode,below = of 4,label=left:2] (2)  {};
    node [below of = a] (b) {};
    node [mynode, below of = 6, label=right:3] (3) {};
    node [mynode, below of = b, label=below:1](1) {};

    draw ;                   
   end{tikzpicture}
  }

  subcaptionbox{}{
   begin{tikzpicture}

       node [mynode,label=above:12] (12) at (0,0) {};
       node [mynode,below left  = of 12,label=left:4] (4)  {};
       node [below of = 12] (a) {};
       node [mynode,below right = of 12,label=right:6] (6) {};
       node [mynode,below = of 4,label=left:2] (2)  {};
       node [below of = a] (b) {};
       node [mynode, below of = 6, label=right:3] (3) {};
       node [mynode, below of = b, label=below:1](1) {};

       draw ;                   
      end{tikzpicture}
  }
  hfil
  subcaptionbox{}{
   begin{tikzpicture}

    node [mynode,label=above:30] (30) at (0,0) {};
    node [mynode,below left  = of 30,label=left:6] (6)  {};
    node [mynode, below = of 30, label=right:10] (10) {};
    node [mynode,below right = of 30,label=right:15] (15) {};
    node [mynode,below = of 6,label=left:2] (2)  {};
    node [mynode, below = of 10, label=right:3] (5) {};
    node[mynode, below = of 15, label=right:5] (5) {};
    node[mynode, below of = 3, label=below:1] (1) {};

    draw ;                   
   end{tikzpicture}
  }
 end{figure}
end{document}
Viewing all 959 articles
Browse latest View live