Debian Codegraph @

texmf-dist/doc/latex/tcolorbox/tcolorbox.doc.sidebyside.tex

raw
1 % !TeX root = tcolorbox.tex
2 % include file of tcolorbox.tex (manual of the LaTeX package tcolorbox)
3 \clearpage
4 \section{Side by Side}\label{sec:sidebyside}%
5 \tcbset{external/prefix=external/sidebyside_}%
6
7 A \emph{side by side} box is a special \refEnv{tcolorbox} where
8 the upper and lower part of the box are set side by side.
9 All boxes of this kind are unbreakable.
10
11 \begin{marker}
12 Further side by side options for code examples are
13 \refKey{/tcb/listing side text},
14 \refKey{/tcb/text side listing},
15 \refKey{/tcb/listing outside text}, and
16 \refKey{/tcb/text outside listing}.
17 \end{marker}
18
19 \subsection{Basic Settings}\label{subsec:sidebyside_basic}
20
21 \begin{docTcbKey}{sidebyside}{\colOpt{=true\textbar false}}{default |true|, initially |false|}
22 Normally, the upper part and the lower part of the box have their positions
23 as their names suggest. If |sidebyside| is set to |true|, the upper part
24 is drawn \emph{left-handed} and the lower part is drawn \emph{right-handed}.
25 Both parts are drawn together with the geometry settings of the upper part but the
26 space is divided horizontally according to the following options.
27 Colors, fonts, and box content additions are used individually.
28 The resulting box is unbreakable.
29
30 \begin{dispExample}
31 \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries}
32
33 \begin{tcolorbox}[title=My title,sidebyside]
34 This is the upper (\textit{left-handed}) part.
35 \tcblower
36 This is the lower (\textit{right-handed}) part.
37 \end{tcolorbox}
38 \end{dispExample}
39
40
41 \begin{dispExample}
42 % \usepackage{lipsum}
43 % \tcbuselibrary{skins}
44 \begin{tcolorbox}[bicolor,sidebyside,righthand width=3cm,
45 sharp corners,boxrule=.4pt,colback=green!5,colbacklower=green!50!black!50]
46 \lipsum[2]
47 \tcblower
48 \includegraphics[width=\linewidth]{goldshade}%
49 \end{tcolorbox}
50 \end{dispExample}
51 \end{docTcbKey}
52
53
54
55 \clearpage
56 \begin{docTcbKey}[][doc updated=2024-11-26]{sidebyside align}{=\meta{alignment}}{no default, initially |center|}
57 Sets the vertical \meta{alignment} for the left-handed and right-handed part.
58
59 Feasible values for \meta{alignment} are:
60 \begin{itemize}
61 \item\docValue{center}: identical to |minipage| option |c|.
62 \item\docValue{top}: identical to |minipage| option |t| (aligns the top
63 lines of the left-handed and right-handed side according to their baselines).
64 \begin{marker}
65 This value of \meta{alignment} needs \refPkg{luacolor} to work properly since version 6.0.0 (2023-02-10).
66 Adding |\strut| may help alternatively to simulate the effect for equal font heights.
67 \end{marker}
68 \item\docValue{bottom}: identical to |minipage| option |b| (aligns the bottom
69 lines of the left-handed and right-handed side according to their baselines).
70 \item\docValue{center seam}: aligns the center of the left-handed and right-handed side.
71 \item\docValue{top seam}: aligns the very top seam of the left-handed and right-handed side.
72 \item\docValue{bottom seam}: aligns the very bottom seam of the left-handed and right-handed side.
73 \end{itemize}
74
75 \begin{exdispExample}{sidebyside_align}
76 \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,nobeforeafter,
77 left=2mm,right=2mm,sidebyside,sidebyside gap=6mm,width=(\linewidth-2mm)/3}
78
79 \begin{tcolorbox}[adjusted title=center,sidebyside align=center]
80 This is a text which is too long for one line.
81 \tcblower
82 This is a short text.
83 \end{tcolorbox}\hfill
84 \begin{tcolorbox}[adjusted title=top,sidebyside align=top]
85 This is a text which is too long for one line.
86 \tcblower
87 This is a short text.
88 \end{tcolorbox}\hfill
89 \begin{tcolorbox}[adjusted title=bottom,sidebyside align=bottom]
90 This is a text which is too long for one line.
91 \tcblower
92 This is a short text.
93 \end{tcolorbox}
94 \end{exdispExample}
95
96
97 \docValue{center}, \docValue{top}, and \docValue{bottom} are identical
98 to the known corresponding |minipage| options.
99 While this is the preferred approach for text content, the result for
100 boxed content like tables or images may not be as expected.
101
102 For such content, one may use \docValue{center seam}, \docValue{top seam},
103 and \docValue{bottom seam}. For example, \docValue{top seam} aligns
104 the very top seam of the left-handed and right-handed side.
105
106
107 \begin{dispExample}
108 \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,
109 size=small,righthand width=4cm,sidebyside,sidebyside gap=6mm,lower separated=false}
110
111 \begin{tcolorbox}[adjusted title=center seam,sidebyside align=center seam]
112 This is my description text for the pictures displayed on the right-handed side.
113 \tcblower
114 \includegraphics[width=\linewidth/2]{goldshade}%
115 \includegraphics[width=\linewidth/2]{blueshade}
116 \end{tcolorbox}
117
118 \begin{tcolorbox}[adjusted title=top seam,sidebyside align=top seam]
119 This is my description text for the pictures displayed on the right-handed side.
120 \tcblower
121 \includegraphics[width=\linewidth/2]{goldshade}%
122 \includegraphics[width=\linewidth/2]{blueshade}
123 \end{tcolorbox}
124
125 \begin{tcolorbox}[adjusted title=bottom seam,sidebyside align=bottom seam]
126 This is my description text for the pictures displayed on the right-handed side.
127 \tcblower
128 \includegraphics[width=\linewidth/2]{goldshade}%
129 \includegraphics[width=\linewidth/2]{blueshade}
130 \end{tcolorbox}
131 \end{dispExample}
132
133
134
135 \end{docTcbKey}
136
137 \clearpage
138 \begin{docTcbKey}{sidebyside gap}{=\meta{length}}{no default, initially |10mm|}
139 Sets the horizontal distance between the left-handed and right-handed part to
140 \meta{length}.
141 \begin{dispExample}
142 \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,nobeforeafter,
143 sidebyside,width=(\linewidth-2mm)/2}
144
145 \begin{tcolorbox}[adjusted title=Wide gap,sidebyside gap=30mm]
146 This is a text which is too long for one line.
147 \tcblower
148 This is a short text.
149 \end{tcolorbox}\hfill
150 \begin{tcolorbox}[adjusted title=Narrow gap,sidebyside gap=1mm]
151 This is a text which is too long for one line.
152 \tcblower
153 This is a short text.
154 \end{tcolorbox}
155 \end{dispExample}
156 \end{docTcbKey}
157
158
159 \begin{docTcbKey}{lefthand width}{=\meta{length}}{no default, initially unset}
160 Sets the width of the left-handed part to the given \meta{length}.
161 \begin{dispExample}
162 \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries}
163
164 \begin{tcolorbox}[title=My title,sidebyside,lefthand width=3cm]
165 This is the upper (\textit{left-handed}) part.
166 \tcblower
167 This is the lower (\textit{right-handed}) part.
168 \end{tcolorbox}
169 \end{dispExample}
170 \end{docTcbKey}
171
172 \enlargethispage*{1cm}
173 \begin{docTcbKey}{righthand width}{=\meta{length}}{no default, initially unset}
174 Sets the width of the right-handed part to the given \meta{length}.
175 \begin{dispExample}
176 \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries}
177
178 \begin{tcolorbox}[title=My title,sidebyside,righthand width=3cm]
179 This is the upper (\textit{left-handed}) part.
180 \tcblower
181 This is the lower (\textit{right-handed}) part.
182 \end{tcolorbox}
183 \end{dispExample}
184 \end{docTcbKey}
185
186 \clearpage
187 \begin{docTcbKey}{lefthand ratio}{=\meta{fraction}}{no default, initially |0.5|}
188 Sets the width of the left-handed part to the given \meta{fraction} of
189 the available space. \meta{fraction} is a value between |0| and |1|.
190 \begin{dispExample}
191 \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries}
192
193 \begin{tcolorbox}[title=My title,sidebyside,lefthand ratio=0.25]
194 This is the upper (\textit{left-handed}) part.
195 \tcblower
196 This is the lower (\textit{right-handed}) part.
197 \end{tcolorbox}
198 \end{dispExample}
199 \end{docTcbKey}
200
201
202 \begin{docTcbKey}{righthand ratio}{=\meta{fraction}}{no default, initially |0.5|}
203 Sets the width of the right-handed part to the given \meta{fraction} of
204 the available space. \meta{fraction} is a value between |0| and |1|.
205 \begin{dispExample}
206 \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries}
207
208 \begin{tcolorbox}[title=My title,sidebyside,righthand ratio=0.25]
209 This is the upper (\textit{left-handed}) part.
210 \tcblower
211 This is the lower (\textit{right-handed}) part.
212 \end{tcolorbox}
213 \end{dispExample}
214 \end{docTcbKey}
215
216
217 \clearpage
218 If one side of a side-by-side box should be adapted to the width of
219 its content, this width has to be computed beforehand.
220 The following example uses a savebox |\mysavebox| to store the picture to determine
221 its width. A more convenient way to handle this task is to use the
222 methods from \zvref{subsec:sidebyside_xparse}.
223
224 \begin{dispExample}
225 % \tcbuselibrary{skins}
226 % \usepackage{lipsum}
227 % \newsavebox\mysavebox % preamble
228 \DeclareTotalTColorBox{\mysidebox}{ O{} +m +m }{
229 bicolor,colback=white,colbacklower=yellow!10,
230 fonttitle=\bfseries,center title,
231 sidebyside,
232 code={\sbox{\mysavebox}{#2}},
233 lefthand width=\wd\mysavebox,
234 drop lifted shadow,
235 #1
236 }
237 {\usebox{\mysavebox}\tcblower#3}
238
239 \mysidebox[title=The Triangle]{%
240 \begin{tikzpicture}
241 \path[fill=red!20,draw=red!50!black]
242 (0,0) node[below]{A} -- (3,1) node[right]{B}
243 -- (1,4) node[above]{C} -- cycle;
244 \end{tikzpicture}%
245 }{%
246 \lipsum[1]
247 }
248 \end{dispExample}
249
250
251 \clearpage
252 \subsection{Advanced Settings}\label{subsec:sidebyside_xparse}
253
254
255 \begin{docCommand}[doc new=2015-11-20]{tcbsidebyside}{\oarg{options}\marg{left-handed content}\marg{right-handed content}}
256 Creates a colored box using more or less arbitrary \meta{options} for a \refEnv{tcolorbox}.
257 The \refKey{/tcb/sidebyside} option is set to |true| and the
258 \meta{left-handed content} and \meta{right-handed content}
259 is filled into the box appropriately.
260 The resulting box is unbreakable.
261
262 \refCom{tcbsidebyside} is not only a shortcut for using
263 a normal \refEnv{tcolorbox} with \refKey{/tcb/sidebyside}, but allows
264 setting further options like \refKey{/tcb/sidebyside adapt}
265 and \refKey{/tcb/sidebyside switch}.
266
267
268 \begin{dispExample}
269 % \tcbuselibrary{skins}
270 % \usepackage{lipsum}
271 \tcbsidebyside[title=The Triangle,
272 sidebyside adapt=left,
273 bicolor,colback=white,colbacklower=yellow!10,
274 fonttitle=\bfseries,center title,drop lifted shadow,
275 ]{%
276 \begin{tikzpicture}
277 \path[fill=red!20,draw=red!50!black]
278 (0,0) node[below]{A} -- (3,1) node[right]{B}
279 -- (1,4) node[above]{C} -- cycle;
280 \end{tikzpicture}%
281 }{%
282 \lipsum[1]
283 }
284 \end{dispExample}
285 \end{docCommand}
286
287
288 \clearpage
289 \begin{docTcbKey}[][doc new=2015-11-20]{sidebyside adapt}{=\meta{side(s)}}{no default, initially |none|}
290 The option allows the left-handed and/or right-handed side to determine the
291 dimensions of the box. This option is only valid inside \refCom{tcbsidebyside}.
292
293 Feasible values for \meta{side(s)} are:
294 \begin{itemize}
295 \item\docValue{none}: no measurement of left-handed and right-handed side.
296 \item\docValue{left}:
297 the actual width of the left-handed content is used to set \refKey{/tcb/lefthand width}.
298 \item\docValue{right}:
299 the actual width of the right-handed content is used to set \refKey{/tcb/righthand width}.
300 \item\docValue{both}:
301 the actual width of the left-handed and right-handed content is used to set
302 \refKey{/tcb/lefthand width}, \refKey{/tcb/righthand width}, and
303 the overall \refKey{/tcb/width}.
304 \end{itemize}
305
306 \begin{dispExample}
307 % \tcbuselibrary{skins}
308 \tcbsidebyside[sidebyside adapt=left,
309 title=Very important table,
310 beamer,colframe=blue!50!black,colback=blue!10,
311 lower separated=false,sidebyside gap=5mm
312 ]{%
313 \begin{tabular}{|l|c|r|}\hline
314 left & center & right\\\hline
315 A & B & C\\\hline
316 D & E & F\\\hline
317 \end{tabular}
318 }{%
319 This table contains the most important figures for
320 all future actions. You may notice that B follows A,
321 C follows B, and so on.
322 }
323 \end{dispExample}
324
325
326
327 \begin{dispExample}
328 % \tcbuselibrary{skins}
329 \tcbsidebyside[sidebyside adapt=right,
330 blanker,sidebyside gap=5mm
331 ]{%
332 \lipsum[2]
333 }{%
334 \begin{tikzpicture}
335 \path[fill=yellow,draw=yellow!75!red] (0,0) circle (1cm);
336 \fill[red] (45:5mm) circle (1mm);
337 \fill[red] (135:5mm) circle (1mm);
338 \draw[line width=1mm,red] (215:5mm) arc (215:325:5mm);
339 \end{tikzpicture}
340 }
341 \end{dispExample}
342
343
344 \begin{dispExample}
345 % \tcbuselibrary{skins}
346 \tcbsidebyside[sidebyside adapt=both,
347 enhanced,center,
348 title=Both sides adapted,
349 attach boxed title to top center={yshift=-2mm},
350 coltitle=black,boxed title style={colback=red!25},
351 segmentation style=solid,colback=red!5,colframe=red!50
352 ]{%
353 \begin{tabular}{|l|c|r|}\hline
354 left & center & right\\\hline
355 A & B & C\\\hline
356 D & E & F\\\hline
357 \end{tabular}
358 }{%
359 \begin{tikzpicture}
360 \path[fill=yellow,draw=yellow!75!red] (0,0) circle (1cm);
361 \fill[red] (45:5mm) circle (1mm);
362 \fill[red] (135:5mm) circle (1mm);
363 \draw[line width=1mm,red] (215:5mm) arc (215:325:5mm);
364 \end{tikzpicture}
365 }
366 \end{dispExample}
367
368 \end{docTcbKey}
369
370
371 \clearpage
372 \begin{docTcbKey}[][doc new=2015-11-20]{sidebyside switch}{\colOpt{=true\textbar false}}{default |true|, initially |false|}
373 If set to |true|, the
374 \meta{left-handed content} and \meta{right-handed content}
375 of \refCom{tcbsidebyside} are switched.
376 Obviously, this option is only valid inside \refCom{tcbsidebyside}.
377
378 The side switching can be made even/odd page sensitive, if used inside
379 \refKey{/tcb/if odd page}.
380
381 \begin{dispExample}
382 % \tcbuselibrary{skins}
383 \tcbsidebyside{Left}{Right}
384
385 \tcbsidebyside[sidebyside switch]{Left}{Right}
386
387 \tcbsidebyside[title=Very important table,
388 if odd page={sidebyside switch,sidebyside adapt=right,flushright title}%
389 {sidebyside adapt=left},
390 beamer,colframe=blue!50!black,colback=blue!10,
391 lower separated=false,sidebyside gap=5mm
392 ]{%
393 \begin{tabular}{|l|c|r|}\hline
394 left & center & right\\\hline
395 A & B & C\\\hline
396 D & E & F\\\hline
397 \end{tabular}
398 }{%
399 This table contains the most important figures for
400 all future actions. You may notice that B follows A,
401 C follows B, and so on.
402 }
403 \end{dispExample}
404
405
406 \end{docTcbKey}
407