Latex: Space remove between parboxes - latex

I try to remove the vertical space between the textboxes. However, since I use the newcommand that opens a new tikzpicture each time, I cannot use setspace I think?
Any other ideas?
\documentclass[10pt,a5paper]{article}
\usepackage[left=10mm, right=10mm, bottom=15mm, top=10mm, footskip=5mm]{geometry}
\usepackage{xcolor}
\xdefinecolor{links}{RGB}{251,212,180}
\xdefinecolor{rechts}{RGB}{214,227,188}
\xdefinecolor{mitte}{RGB}{218,216,215}
\usepackage{tikz}
\usepackage{varwidth}
\usetikzlibrary{shapes}
\tikzstyle{sms} = [rectangle callout, draw,very thick, rounded corners, minimum height=20pt]
\newcommand{\smsr}[1]{\begin{flushright}
\begin{tikzpicture}
\node [sms, align=right,callout relative pointer={(0.5,0)}, fill=rechts] {\begin{varwidth}{0.7\textwidth}{#1}\end{varwidth}};
\end{tikzpicture}\end{flushright}}
\newcommand{\smsl}[1]{\begin{flushleft}
\begin{tikzpicture}
\node[sms, align=left,callout relative pointer={(-0.5,0)}, fill=links] {\begin{varwidth}{0.7\textwidth}{#1}\end{varwidth}};
\end{tikzpicture}\end{flushleft} }
\newcommand{\datum}[1]{\begin{center} \begin{tikzpicture}
\node[rectangle, very thick, text width=0.4\textwidth, rounded corners, draw,align=center, fill=mitte] {#1};
\end{tikzpicture} \end{center}}
\begin{document}
\small
\datum{Saturday, 22.July}
\smsl{Send Hallo}
\smsr{Answer Bye. Very long line to show the function of automatic line-breaking.}
\smsr{Still awake?}
\end{document}

Inserting each tikzpicture inside another environment may insert unwanted vertical spacing. Perhaps don't use them:
\documentclass[10pt,a5paper]{article}
\usepackage[left=10mm, right=10mm, bottom=15mm, top=10mm, footskip=5mm]{geometry}
\usepackage{xcolor}
\xdefinecolor{links}{RGB}{251,212,180}
\xdefinecolor{rechts}{RGB}{214,227,188}
\xdefinecolor{mitte}{RGB}{218,216,215}
\usepackage{tikz}
\usepackage{varwidth}
\usetikzlibrary{shapes}
\tikzstyle{sms} = [rectangle callout, draw,very thick, rounded corners, minimum height=20pt]
\newcommand{\smsr}[1]{\hfill
\begin{tikzpicture}
\node [sms, align=right,callout relative pointer={(0.5,0)}, fill=rechts] {\begin{varwidth}{0.7\textwidth}{#1}\end{varwidth}};
\end{tikzpicture}
\par}
\newcommand{\smsl}[1]{%
\begin{tikzpicture}
\node[sms, align=left,callout relative pointer={(-0.5,0)}, fill=links] {\begin{varwidth}{0.7\textwidth}{#1}\end{varwidth}};
\end{tikzpicture}
\par}
\newcommand{\datum}[1]{%
\begin{center}
\begin{tikzpicture}
\node[rectangle, very thick, text width=0.4\textwidth, rounded corners, draw,align=center, fill=mitte] {#1};
\end{tikzpicture}
\end{center}}
\setlength{\parindent}{0pt}
\begin{document}
\small
\datum{Saturday, 22 July}
\smsl{Send Hallo}
\smsr{Answer Bye. Very long line to show the function of automatic line-breaking.}
\smsr{Still awake?}
\end{document}
I also removed any paragraph indent, but kept the title set with some distance between the following text bubbles (using center).
An alternative to the above, if you plan on using \smsl, \smsr and \datum for everything, would be to use \raggedright, \raggedleft and \centering respectively (rather than \hfill for \smsl and center for datum).

Related

How to set the maximum width of an input node in an algorithm flowchart with LateX and tikz

I would like to set the width for a node, in particular, an Input/Output node in Tikz.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right
angle=110, minimum width=3cm, minimum height=1cm, text centered,
draw=black, fill=blue!30]
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (in1) [io] {Input};
\end{tikzpicture}
\end{document}
The code above generates the following node:
As the text inside grows so does the width of the Input node. But my question is if there is a way to set the width of the Input node beforehand or to give the Input node a maximum width.
You can use the trapezium stretches=true option together with a fixed text width to make sure all your nodes have the same width.
If you have really long text, you could use the adjustbox option to automatically scale the text down to fit into your node:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzset{io/.style={
trapezium,
trapezium left angle=70,
trapezium right angle=110,
text width=3cm,
minimum height=1cm,
text centered,
draw=black,
fill=blue!30,
trapezium stretches=true
}}
\usepackage{adjustbox}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (in1) [io] {Input};
\node at (0,-2) [io] {\adjustbox{max width=3cm}{long text overflowing the shape}};
\node at (0,-4) [io] {Input Input};
\end{tikzpicture}
\end{document}

How to avoid tiltled lines in circuitikz?

I want the line on the left to end right at the y-coordinate of the SPDT input so I can connect them seamlessly with a straight line. As you can see, the line on the left ends a bit lower than the SPDT input which causes the connecting line to be tilted
Is there a way to automatically adjust the length? I'd rather avoid inching towards an acceptable result by adjusting the length over and over again manually.
Here is the code
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{circuitikz}
\begin{document}
\begin{figure}
\begin{circuitikz}
\node [spdt, rotate=90] (S) {};
\draw
(S.in) to [C] ++(0,-2)
to ++(-2,0)
to [V] ++(0,3)
to(S.out 1);
\end{circuitikz}
\end{figure}
\end{document}
Instead of adjusting the length on the left, I would just make sure that it is above the switch and then use -| to connect it with first an horizontal segment and then a vertical segment:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{circuitikz}
\begin{document}
\begin{figure}
\begin{circuitikz}
\node [spdt, rotate=90] (S) {};
\draw
(S.in) to [C] ++(0,-2)
to ++(-2,0)
to [V] ++(0,3.5)
-| (S.out 1)
;
\end{circuitikz}
\end{figure}
\end{document}

Using an environment such as itemize in a tikz node shifts vertical alignment

If I use an environment in a tikz node, the vertical alignment is shifted. The following example shows the difference, in the first case, where no environment is used, everything is fine.
\begin{frame}
% alignment is correct without using itemize
\begin{tikzpicture}
\node[text width=\textwidth, text centered,fill=yellow, fill opacity=0.4,text opacity=1, rounded corners, inner sep= 0em, outer sep=0em]{test};
\end{tikzpicture}
% alignment is shifted vertically
\begin{tikzpicture}
\node[text width=\textwidth, text centered,fill=yellow, fill opacity=0.4,text opacity=1, rounded corners, inner sep= 0em, outer sep=0em]{\begin{itemize}
\item test
\end{itemize}};
\end{tikzpicture}
\end{frame}
You can workaround the problem like this:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
% alignment is correct without using itemize
\begin{tikzpicture}
\node[text width=\textwidth, text centered,fill=red, fill opacity=0.4,text opacity=1, rounded corners, inner sep= 0em, outer sep=0em]{test};
\end{tikzpicture}
\bigskip
% alignment is shifted vertically
\begin{tikzpicture}[baseline]
\node[text width=\textwidth, text centered,fill=red, fill opacity=0.4,text opacity=1, rounded corners, inner sep= 0em, outer sep=0em]{\begin{minipage}{\textwidth}\begin{itemize}
\item test
\end{itemize}\end{minipage}};
\end{tikzpicture}
\end{frame}
\end{document}

Ignore margins and wrap text when adding pictures in Latex

I would like to add images in the top left/right or bottom left/right in a two-column page while ignoring the margins and having the text wrap around the picture. How can I also extend the solution to include half page images while ignoring the margins and with text wrapping.
I tried tikz package, but the text doesn't wrap around even when I use the wrapfig package.
For example, this is the code I used to insert image on the top left side of the page:
\documentclass[twocolumn, 12pt]{book}
\usepackage{lipsum}
\usepackage{tikz}
\begin{document}
\lipsum[1-3]
\begin{tikzpicture} [remember picture, overlay]
\node[anchor=north west,yshift=-1.5pt,xshift=1pt]%
at (current page.north west)
{\includegraphics[width=0.5\paperwidth,height=0.5\paperheight]{example.jpg}};
\end{tikzpicture}
\lipsum[1-3]
\end{document}
This results in the picture at the desired position, but the text is obscured behind the image. Thank you!
Not very pretty, but does the job I think (using geometry package only to get the correct values for top margin):
\documentclass[twocolumn, 12pt]{book}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{geometry}
\begin{document}
\begin{tikzpicture} [remember picture, overlay]
\node[anchor=north west]%
at (current page.north west)
{\includegraphics[width=0.46\paperwidth,height=0.5\paperheight]{example.png}};
\end{tikzpicture}
\vspace*{\dimexpr(0.5\paperheight-\voffset-1in-\headsep-\headheight)}
\lipsum[1-3]
\lipsum[1-3]
\end{document}

Positioning of hyperlinked shapes with matrix in tikz

I can draw a hyperlinked shape in tikz using the following code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{hyperref}
\begin{document}
\begin{tikzpicture}
\node {%
\href{http://www.stackoverflow.com}{%
\begin{tikzpicture}
\filldraw[blue] circle(1cm) node [white] {Click};
\end{tikzpicture}}};
\end{tikzpicture}
\end{document}
Now I would like to organize my shapes using the matrix, and have one of the shapes hyperlinked. It almost works, but I am not able to align the hyperlinked shape with the rest of the shapes, and it is bigger than the other shapes:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{hyperref}
\begin{tikzpicture}
\matrix [matrix of nodes, row sep = 1cm, column sep=1cm, nodes={circle, draw}]
{% First row:
1 & 2 \\
% second row:
\path node {\href{http://www.stackoverflow.com}{%
\begin{tikzpicture}
\node {3};
\end{tikzpicture}}}; & 4\\
};
\end{tikzpicture}
\end{document}
I get the following result:
(source: picture.im)
My question is: How could I align shape 3 in the picture above with the other shapes, and get rid of the outer circle?
I think you're aiming too high and your second {tikzpicture} is messing up your layout.
What do you think about the code below? Is that what you've been looking for?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage[pdftex,active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\usepackage{hyperref}
\begin{document}
\begin{tikzpicture}
\matrix [matrix of nodes, row sep = 1cm, column sep=1cm, nodes={circle, draw}]
{%
1 & 2\\%
\href{http://stackoverflow.com}{3} & 4\\%
};
\end{tikzpicture}
\end{document}
BTW: the \PreviewEnvironment{tikzpicture} is not really needed, but it makes for a nice, cropped pdf...

Resources