如何将 tcolorbox 置于 KOMA-script 文章的部分标题中央

如何将 tcolorbox 置于 KOMA-script 文章的部分标题中央

我正在尝试将零件标题居中。
这是 MWE:

  % Preview source code

%% LyX 2.3.2-2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[a4paper,twocolumn,english,hebrew,numbers=noenddot]{scrartcl}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{fontspec}
\setlength{\parindent}{0bp}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth

\def\@outputdblcol{%
  \if@firstcolumn
    \global \@firstcolumnfalse
    \global \setbox\@leftcolumn \box\@outputbox
  \else
    \global \@firstcolumntrue
    \setbox\@outputbox \vbox {%
      \hb@xt@\textwidth {%
      \kern\textwidth \kern-\columnwidth %**
      \hb@xt@\columnwidth {%
         \box\@leftcolumn \hss}%
      \kern-\textwidth %**
      \hfil
      {\normalcolor\vrule \@width\columnseprule}%
      \hfil
      \kern-\textwidth  %**
      \hb@xt@\columnwidth {%
         \box\@outputbox \hss}%
      \kern-\columnwidth \kern\textwidth %**
    }%
  }%
  \@combinedblfloats
  \@outputpage
  \begingroup
  \@dblfloatplacement
  \@startdblcolumn
  \@whilesw\if@fcolmade \fi
  {\@outputpage
    \@startdblcolumn}%
  \endgroup
  \fi
}
\@mparswitchtrue

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}
\newfontfamily\hebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
\newfontfamily\hebrewfontsf[Script=Hebrew]{Bellefair}

\usepackage{adforn}
\usepackage{tcolorbox}
\setkomafont{part}{\itshape}
\setkomafont{partnumber}{}
\renewcommand*{\partformat}{חלק~ :\thepart~~}
\renewcommand\partheadmidvskip{}
\renewcommand\partlineswithprefixformat[3]{\hfill\begin{center}\fontsize{20pt}{20pt}\selectfont{\begin{tcolorbox}[center]\underline{\adforn{36} 
            #2#3 \adforn{64}}\end{tcolorbox}}\end{center}\hfill}
\AtBeginDocument{\renewcommand*{\raggedpart}{\centering}}

\makeatother

\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\begin{document}

\part{שלום}
\end{document}

输出如下:
在此处输入图片描述

我尝试了许多命令(正如您在 MWE 上看到的那样)但是框仍然在正确位置。

您知道我怎样才能将它移至中心吗?

重要提示:当我删除 tcolorbox 时,它工作正常(标题移动到中心) - 问题是当我添加颜色框时。

答案1

把事情简单化:

\documentclass{scrartcl}
\usepackage{tcolorbox}
\renewcommand*{\raggedpart}{\centering}
\renewcommand*{\partformat}{\partname~\thepart\autodot\enskip}
\renewcommand\partlineswithprefixformat[3]{%
  \tcbox{\underline{#2#3}}%
}
%\usepackage{showframe}% to see the page areas
\begin{document}
\part{Testpart}
\end{document}

居中零件盒

或使用twocolumn文档类的选项:

\documentclass[twocolumn]{scrartcl}
\usepackage{tcolorbox}
\renewcommand*{\raggedpart}{\centering}
\renewcommand*{\partformat}{\partname~\thepart\autodot\enskip}
\renewcommand\partlineswithprefixformat[3]{%
  \tcbox{\underline{#2#3}}%
}
%\usepackage{showframe}% to see the page areas
\begin{document}
\twocolumn[\part{Testpart}]
\end{document}

但请注意:此建议仅在您不需要换行符时才有效。并且\twocolumn始终开始新的一页。

相关内容