TeX - LaTeX Asked on April 10, 2021
How do you explicitly widen a sequence diagram created with pgf-umlsd
, or, ideally, direct it to be as wide as required to show its labels without overlap?
Here is a very simple standalone
document that uses A Long Method Name
as the "call" part of a sequence diagram. Unfortunately, this overlaps with the two sequences under Client
and Server
.
Is it possible to direct the sequencediagram
to be as wide as necessary to accommodate the text?
I consulted a few answers on this site and this document, which explains how to use postlevel
to wrap things. This answer suggests using unitbox
, but so far that has only adjusted the vertical spacing, it hasn’t forced the diagram to become wider. The answers to [this question(https://tex.stackexchange.com/q/249200) do not seem to show a way to configure the sequence diagram as a whole to adapt to the width of its labels.
documentclass[preview]{standalone}
usepackage{pgf-umlsd}
begin{document}
begin{figure}
begin{sequencediagram}
newthread{A}{Client}{}
newthread{B}{Server}{}
begin{call}{A}{A Long Method Name}{B}{}
end{call}
end{sequencediagram}
end{figure}
end{document}
Looking a little bit at the code, it doesn't at first glance look like there's a way of doing that as the package is written. A possible workaround would be to define a new macro for threads that includes another mandatory argument for an xshift of said thread. It's a bit crude, but works for this specific case.
(By the way, the bounding box is a bit wrong, as you can see if you run the example below, I haven't tried fixing that.)
documentclass{standalone}
usepackage{pgf-umlsd}
% based on newthread macro from pgf-umlsd.sty
% add fourth argument (third mandatory) that defines the xshift of a thread.
% that argument gets passed to newinst, which has an optional
% argument that defines the shift
newcommand{newthreadShift}[4][gray!30]{
newinst[#4]{#2}{#3}
stepcounter{threadnum}
node[below of=insttheinstnum,node distance=0.8cm] (threadthethreadnum) {};
tikzstyle{threadcolorthethreadnum}=[fill=#1]
tikzstyle{instcolor#2}=[fill=#1]
}
begin{document}
begin{sequencediagram}
newthread{A}{Client}
newthreadShift{B}{Server}{4cm}
begin{call}{A}{A Long Method Name}{B}{}
end{call}
end{sequencediagram}
end{document}
Answered by Torbjørn T. on April 10, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP