KOMA-script 文章中如何將 tcolorbox 置於零件標題的中心

KOMA-script 文章中如何將 tcolorbox 置於零件標題的中心

我正在嘗試將部分標題居中。
這是 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總是開始新的一頁。

相關內容