I am making a conversation and I need to draw some shapes, and place them properly along the page. The shapes are the following:
- A white rectangle with a little crest (called
mestart):
- A white rectangle without a crest (called
me):
- A green rectangle with a little crest (called
youstart):
- A green rectangle without a crest (called
you):
- A blue rectangle with rounded corners (called
exnumber):
What I want
I want to produce the following conversation:
To consider:
- All the rectangles (except
exnumber) can have inside:- Only text (normal text, bulleted list, numbered list etc.), or
- Only one image (it can be a
tikzpicture), or - Text & sample code (for instance
listingspackage can be a good example).
- These rectangles must have a max width and a space between them:
(also the images should have the same max width). - The blue rectangle i.e.
exnumbershould be placed centered on the page with an automatic numeration and restarted when the section ends. For example: in Section 1Exercise 1,Exercise 2,Exercise 3. In Section 2:Exercise 1,Exercise 2.
What I have done
Please consider this MWE:
\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes.misc, positioning}
\usetikzlibrary{decorations.text}
\usetikzlibrary{shapes.symbols}
\begin{document}
\begin{tikzpicture}
\node (1) [rounded corners=.2cm,inner sep=.3cm,align=right,fill=blue] {Exercise 1};
\end{tikzpicture}
\begin{tikzpicture}
\node (1) [draw,rounded corners=.2cm,inner sep=.5cm,align=left] {rounded rectangle\\asas};
\end{tikzpicture}
\begin{tikzpicture}
\node (1) [rounded corners=.2cm,inner sep=.5cm,align=right,fill=green] {This is a rounded rectangle\\Text\\ a \\ a \\ a};
\end{tikzpicture}
\end{document}
EDIT Some changes to edit #4 of the amazing Schrödinger's cat's answer with some implementations:
- Added
\maxwidthand\maxheight. - Since I need to add a lot of images to the conversation, I have created four new types of shapes: the 4 ones but with the word
Imageafter the names. This includes\includegraphics[max height=\maxheight,max width=\maxwidth]{#2}. \begin{varwidth}{\maxwidth}added to the normal 4 shapes.- Added tabs space and some information to the code.
Final result:
\documentclass{article}
\usepackage{blindtext}
\def\maxwidth{16cm}
\def\maxheight{20cm}
\usepackage[a4paper,margin=.25in,footskip=0.25in]{geometry}
\usepackage[export]{adjustbox} % Loads also graphicx
\usepackage{varwidth}
\usepackage{tikz}
\usetikzlibrary{positioning}
% From https://tex.stackexchange.com/revisions/529773/4
\tikzset{basic/.style={rounded corners=.2cm,inner sep=.5cm},
basic L/.style={basic,align=left,fill=white,anchor=north west,
font=\sffamily,outer sep=0pt},
my callout L/.style={basic L,
append after command={pic[fill=white]{callout corner L}}},
basic R/.style={basic,align=right,fill=green!60!black,anchor=north east,
font=\sffamily,outer sep=0pt},
my callout R/.style={basic R,
append after command={pic[fill=green!60!black]{callout corner R}}},
pics/callout corner L/.style={code={
\path[pic actions] ([xshift=3mm]\tikzlastnode.north west) -- ++ (-9mm,0)
-- ([yshift=-6mm]\tikzlastnode.north west);}},
pics/callout corner R/.style={code={
\path[pic actions] ([xshift=-3mm]\tikzlastnode.north east) -- ++ (9mm,0)
-- ([yshift=-6mm]\tikzlastnode.north east);}},
exercise/.style={rounded corners=.2cm,inner sep=.3cm,align=right,
fill=blue,anchor=north,font=\sffamily,text=white},
whatsapp/.cd,vdist/.initial=3mm,hdist/.initial=6mm
}
% Added varwidth to set a max width for each of the shapes. From https://tex.stackexchange.com/a/46479/152550
% MeStart
\newcommand{\MeStart}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\pgfkeysvalueof{/tikz/whatsapp/hdist},0) node[my callout L,alias=tmp,#1] {\begin{varwidth}{\maxwidth}#2\end{varwidth}};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% Me
\newcommand{\Me}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\pgfkeysvalueof{/tikz/whatsapp/hdist},0) node[basic L,alias=tmp,#1] {\begin{varwidth}{\maxwidth}#2\end{varwidth}};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% YouStart
\newcommand{\YouStart}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\textwidth-\pgfkeysvalueof{/tikz/whatsapp/hdist},0) node[my callout R,alias=tmp,#1] {\begin{varwidth}{\maxwidth}#2\end{varwidth}};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% You
\newcommand{\You}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\textwidth-\pgfkeysvalueof{/tikz/whatsapp/hdist},0) node[basic R,alias=tmp,#1] {\begin{varwidth}{\maxwidth}#2\end{varwidth}};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% Exercise
\newcommand{\Exercise}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\textwidth/2,0) node[exercise,alias=tmp,#1] {#2};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% max height/width for includegraphics from https://tex.stackexchange.com/a/47252/152550
% MeStartImage
\newcommand{\MeStartImage}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\pgfkeysvalueof{/tikz/whatsapp/hdist},0) node[my callout L,alias=tmp,#1] {\includegraphics[max height=\maxheight,max width=\maxwidth]{#2}};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% MeImage
\newcommand{\MeImage}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\pgfkeysvalueof{/tikz/whatsapp/hdist},0) node[basic L,alias=tmp,#1] {\includegraphics[max height=\maxheight,max width=\maxwidth]{#2}};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% YouStartImage
\newcommand{\YouStartImage}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\textwidth-\pgfkeysvalueof{/tikz/whatsapp/hdist},0) node[my callout R,alias=tmp,#1] {\includegraphics[max height=\maxheight,max width=\maxwidth]{#2}};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% YouImage
\newcommand{\YouImage}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\textwidth-\pgfkeysvalueof{/tikz/whatsapp/hdist},0) node[basic R,alias=tmp,#1] {\includegraphics[max height=\maxheight,max width=\maxwidth]{#2}};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
\begin{document}
\begin{tikzpicture}[overlay,remember picture]
\fill[blue!20] (current page.south west) rectangle (current page.north east);
\end{tikzpicture}
\MeStart{\blindtext[1]\\ Text}
\MeImage[scale=0.5]{example-image}
\YouStartImage[scale=2]{example-image-duck}
\Exercise{How many marmots?}
\You{\Blindtext[1]}
\end{document}




calloutshapes which look similar but not identical to what you have. Do you want the exact shape, or is something similar OK? – Feb 24 '20 at 05:35