As the question described, I use the sidebyside "wheel" of the tcolorbox
package to create an environment for achieve "left: text, and right: figure". Is it possible to create this "wheel" without loading the tcolorbox
package?
What's more, I don't want to use the minipage
or paracol
environment, because for the former I need to type \noindent
manually and for the latter, I need to type \vfill
twice to center the figure on the right vertically.
The following is the MWE:
\documentclass{article}
\usepackage{lipsum,amsthm,tcolorbox}
\NewTColorBox { textfig } { O { .64\linewidth } }
{
sidebyside, sidebyside gap = .02\linewidth, boxsep = 0pt,
left = 0pt, right = 0pt, top = 3pt, bottom = 0pt,
lefthand width = #1, standard jigsaw, opacityback = 0, frame empty
}
\newtheorem{problem}{Problem}
\begin{document}
\begin{textfig}
\begin{problem}
\lipsum[2]
\end{problem}
\tcblower
\centering
\includegraphics[width = .5\linewidth]{example-image-a}
\end{textfig}
\end{document}
封装一下 minipage
,设置 \parindent=0pt
。
\documentclass{article}
\ExplSyntaxOn
\box_new:N \l__skyrmion_left_box
\box_new:N \l__skyrmion_right_box
\box_new:N \l__skyrmion_seg_box
\keys_define:nn { skyrmion }
{
lefthand~ratio .fp_set:N = \l__skyrmion_left_ratio_fp ,
lefthand~width .dim_set:N = \l__skyrmion_left_dim ,
righthand~ratio .dim_set:N = \l__skyrmion_right_ratio_fp ,
righthand~width .dim_set:N = \l__skyrmion_right_dim ,
sidebyside~gap .dim_set:N = \l__skyrmion_gap_dim ,
sidebyside~gap .initial:n = 10mm ,
before~left .tl_set:N = \l__skyrmion_before_left_tl ,
before~right .tl_set:N = \l__skyrmion_before_right_tl ,
}
\cs_new_protected:Npn \twopartsplit
{
\dim_compare:nNnTF \l__skyrmion_right_dim < { 10sp }
{
%% Width is too small! Abort!
}
{
\__skyrmion_twopart_end_save:
\__skyrmion_twopart_save:NN \l__skyrmion_right_box \l__skyrmion_right_dim
\l__skyrmion_before_right_tl \ignorespaces
}
}
\NewDocumentEnvironment{twopart}{ O{} }
{
\par \keys_set:nn { skyrmion } {#1}
\__skyrmion_calc_width:
\__skyrmion_twopart_save:NN \l__skyrmion_left_box \l__skyrmion_left_dim
\l__skyrmion_before_left_tl \ignorespaces
}
{
\__skyrmion_twopart_end_save:
\__skyrmion_twopart_typeset:
}
\cs_new:Npn \__skyrmion_calc_width:
{
\bool_lazy_and:nnTF
{ \dim_compare_p:nNn \l__skyrmion_left_dim = \c_zero_dim }
{ \dim_compare_p:nNn \l__skyrmion_right_dim = \c_zero_dim }
{
\bool_lazy_and:nnTF
{ \fp_compare_p:nNn { abs ( \l__skyrmion_left_ratio_fp ) } < { 0.0001 } }
{ \fp_compare_p:nNn { abs ( \l__skyrmion_right_ratio_fp ) } < { 0.0001 } }
{
\dim_set:Nn \l__skyrmion_left_dim { 0.5\linewidth - 0.5\l__skyrmion_gap_dim }
\dim_set:Nn \l__skyrmion_right_dim { \l__skyrmion_left_dim }
}
{
\fp_compare:nNnTF { abs ( \l__skyrmion_left_ratio_fp ) } < { 0.0001 }
{
\dim_set:Nn \l__skyrmion_right_dim
{
\fp_use:N \l__skyrmion_right_ratio_fp
\dimexpr \linewidth - \l__skyrmion_gap_dim \relax
}
\dim_set:Nn \l__skyrmion_left_dim
{ \linewidth - \l__skyrmion_gap_dim - \l__skyrmion_right_dim }
}
{
\dim_set:Nn \l__skyrmion_left_dim
{
\fp_use:N \l__skyrmion_left_ratio_fp
\dimexpr \linewidth - \l__skyrmion_gap_dim \relax
}
\dim_set:Nn \l__skyrmion_right_dim
{ \linewidth - \l__skyrmion_gap_dim - \l__skyrmion_left_dim }
}
}
}
{
\dim_compare:nNnTF \l__skyrmion_left_dim = \c_zero_dim
{
\dim_set:Nn \l__skyrmion_left_dim
{ \linewidth - \l__skyrmion_gap_dim - \l__skyrmion_right_dim }
}
{
\dim_set:Nn \l__skyrmion_right_dim
{ \linewidth - \l__skyrmion_gap_dim - \l__skyrmion_left_dim }
}
}
}
\cs_new:Npn \__skyrmion_twopart_save:NN #1 #2
{
\hbox_set:Nw #1
\minipage {#2}
\setlength{\parindent}{0pt}
}
\cs_new:Npn \__skyrmion_twopart_end_save:
{
\endminipage
\hbox_set_end:
}
\cs_new:Npn \__skyrmion_seg: { } % 画线,可以用 tikz 等等
\cs_new:Npn \__skyrmion_twopart_typeset:
{
\hbox_to_wd:nn { \linewidth }
{
\hbox_set:Nn \l__skyrmion_seg_box { \__skyrmion_seg: }
\hbox_unpack_drop:N \l__skyrmion_left_box
\hss \clap { \box_use_drop:N \l__skyrmion_seg_box } \hss
\hbox_unpack_drop:N \l__skyrmion_right_box
}
}
\ExplSyntaxOff
\usepackage{lipsum,amsthm,tcolorbox}
\NewTColorBox { textfig } { O { .64\linewidth } }
{
sidebyside, sidebyside gap = .02\linewidth, boxsep = 0pt,
left = 0pt, right = 0pt, top = 3pt, bottom = 0pt,
lefthand width = #1, standard jigsaw, opacityback = 0, frame empty
}
\newtheorem{problem}{Problem}
\begin{document}
\begin{textfig}
\begin{problem}
\lipsum[2]
\end{problem}
\tcblower
\centering
\includegraphics[width = .5\linewidth]{example-image-a}
\end{textfig}
\begin{twopart}[sidebyside gap=.02\linewidth, lefthand width=.64\linewidth]
\begin{problem}
\lipsum[2]
\end{problem}
\twopartsplit
\centering
\includegraphics[width = .5\linewidth]{example-image-a}
\end{twopart}
\end{document}
也可以用 coffin
,代码是相似的。
只有用
paracol
实现才可以分页,其它都不行。