我想創建一個居中的彩色 parbox,但是儘管我使用包包定義了寄宿生幾何學,parbox 的左側邊距大於右側邊距。
感謝幫助
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage[a4paper,top=1cm,left=2cm,right=2cm]{geometry}
\usepackage{graphicx}
\begin{document}
\definecolor{Blau1}{RGB}{0,97,175}
\definecolor{Blau2}{RGB}{86,189,218}
\definecolor{Blau3}{RGB}{212,239,252} % Define a custom color for the heading box
\colorbox{Blau3}{ % Creates a highlight behind the text using the previously-defined navy color
\parbox[t]{\linewidth}{ % Creates a box to take up the entire line width
\centering
\vspace*{14pt} % Whitespace above the text
\color{Blau1} \center{\textbf{\Large REPORT}} % Right-aligned heading text
\vspace*{14pt} % Whitespace below the text
}}
\end{document}
答案1
您需要刪除顏色框之前的縮排和框的自然填充(也許以另一種方式調用,我不確定)。對於後者,我使用了該calc
包並將 parbox 的長度設為\textwidth-2\fboxsep
,從而textwidth
減去自然填充。
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage[a4paper,top=1cm,left=2cm,right=2cm]{geometry}
\usepackage{graphicx}
\usepackage{showframe}
\usepackage{calc}
\begin{document}
\definecolor{Blau1}{RGB}{0,97,175}
\definecolor{Blau2}{RGB}{86,189,218}
\definecolor{Blau3}{RGB}{212,239,252}
\noindent\colorbox{Blau3}{% new code here
\parbox[t]{\textwidth-2\fboxsep}{% new code here
\centering
\vspace*{14pt}
\color{Blau1} \center{\textbf{\Large REPORT}}
\vspace*{14pt}
}}
\end{document}