I first removed distracting stuff like the `hbox` and `varwidth upper` options. If you really want the `0.9\linewidth` thing, you can readd these options (see below). Regarding the green box that is of interest here, I used:
```
\tcbset{flush right/.show code}
```
This led me to define the following style:
```
my flush right/.style={
enlarge left by=\linewidth - (\kvtcb@width + #1),
},
```
which appears to do what you want. I also added the `mywidth` style for convenience and to comply with the DRY principle.
```
\documentclass[final]{ltugboat}
\usepackage[skins]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{tikzlings}
\usepackage{blindtext}
\makeatletter
\newlength{\carlatex@len}
\newdimen\myrightskip
\myrightskip=9mm % for the green box
\tcbset{
commonoptions/.style={
enhanced, show bounding box,
fonttitle=\bfseries\scriptsize,
titlerule=0pt, boxrule=0pt, boxsep=0pt,
toptitle=6pt, bottomtitle=4pt,
opacityframe=0,
},
my flush right/.style={
enlarge left by=\linewidth - (\kvtcb@width + #1),
},
mywidth/.code={%
\settowidth{\carlatex@len}{\bfseries\scriptsize #1}%
\tcbset{width=\carlatex@len + \myrightskip}%
},
}
\makeatother
\newtcolorbox{receivedmsg}[2][]{
commonoptions,
left skip=9mm,
overlay={
\pic[scale=.3] at ([shift={(-6mm,-6mm)}]frame.north west) {bear};
\path[fill=yellow!30] (frame.north) -- ([xshift=-3mm]frame.north west) --
([yshift=-3mm]frame.north west) -- cycle;
},
coltitle=red, colbacktitle=yellow!30, colback=yellow!30,
title={#2}, #1,
}
\newtcolorbox{sentmsg}[2][]{
commonoptions,
my flush right=\myrightskip, right skip=\myrightskip,
overlay={
\pic[scale=.3] at ([shift={(6mm,-6mm)}]frame.north east) {elephant};
\path[fill=green!30] (frame.north) -- ([xshift=3mm]frame.north east) --
([yshift=-3mm]frame.north east) -- cycle;
},
coltitle=blue, colbacktitle=green!30, colback=green!30,
title={#2}, #1,
}
\begin{document}
\blindtext
\begin{receivedmsg}{Tostin:}
You know, I spent a lot of years disliking women. But I don't dislike you.
\end{receivedmsg}
\begin{sentmsg}[mywidth={Edna:}]{Edna:}
Oh?
\end{sentmsg}
\begin{receivedmsg}{Tostin:}
You're not a woman. You're more than a woman. You're a \emph{mechanic}.
\end{receivedmsg}
\blindtext
\end{document}
```
![new.png](/image?hash=cab696e033e4f11dbacbf5ad642e9affee33388e52f9f75c7781e77e17d8c488)
# With the `varwidth upper` style
`varwidth upper=.9\linewidth` seemed a bit too short here (I guess it is influenced by our options that leave room for the callout). The following code is essentially the same as above but uses `hbox, varwidth upper=.8\linewidth` for `receivedmsg` boxes.
Note that the `mywidth` style, which relies on `/tcb/width`, is incompatible with `hbox` and `varwidth upper`; therefore, in this example I have only used these two styles in `receivedmsg` boxes.
```
\documentclass[final]{ltugboat}
\usepackage[skins]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{tikzlings}
\usepackage{varwidth}
\usepackage{blindtext}
\makeatletter
\newlength{\carlatex@len}
\newdimen\myrightskip
\myrightskip=9mm % for the green box
\tcbset{
commonoptions/.style={
enhanced, show bounding box,
fonttitle=\bfseries\scriptsize,
titlerule=0pt, boxrule=0pt, boxsep=0pt,
toptitle=6pt, bottomtitle=4pt,
opacityframe=0,
},
my flush right/.style={
enlarge left by=\linewidth - (\kvtcb@width + #1),
},
mywidth/.code={%
\settowidth{\carlatex@len}{\bfseries\scriptsize #1}%
\tcbset{width=\carlatex@len + \myrightskip}%
},
}
\makeatother
\newtcolorbox{receivedmsg}[2][]{
commonoptions,
hbox, varwidth upper=.8\linewidth,
left skip=9mm,
overlay={
\pic[scale=.3] at ([shift={(-6mm,-6mm)}]frame.north west) {bear};
\path[fill=yellow!30] (frame.north) -- ([xshift=-3mm]frame.north west) --
([yshift=-3mm]frame.north west) -- cycle;
},
coltitle=red, colbacktitle=yellow!30, colback=yellow!30,
title={#2}, #1,
}
\newtcolorbox{sentmsg}[2][]{
commonoptions,
my flush right=\myrightskip, right skip=\myrightskip,
overlay={
\pic[scale=.3] at ([shift={(6mm,-6mm)}]frame.north east) {elephant};
\path[fill=green!30] (frame.north) -- ([xshift=3mm]frame.north east) --
([yshift=-3mm]frame.north east) -- cycle;
},
coltitle=blue, colbacktitle=green!30, colback=green!30,
title={#2}, #1,
}
\begin{document}
\blindtext
\begin{receivedmsg}{Tostin:}
You know, I spent a lot of years disliking women. But I don't dislike you.
\end{receivedmsg}
\begin{sentmsg}[mywidth={Edna:}]{Edna:}
Oh?
\end{sentmsg}
\begin{receivedmsg}{Tostin:}
You're not a woman. You're more than a woman. You're a \emph{mechanic}.
\end{receivedmsg}
\blindtext
\end{document}
```
![new2.png](/image?hash=80995db0733c331088b90435ded45a745867216d04931ad21bf2506a4851a217)