自定义头部颜色仅限文本但不包含整个框

自定义头部颜色仅限文本但不包含整个框

\resheading我正在尝试为定义为的自定义标题着色

\newcommand{\resheading}[1]{\vspace{-15pt}
  \parbox{\textwidth}{
    \begin{shaded}
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{0pt}%
\framebox[\textwidth][l]{\setlength{\fboxsep}{2pt}\colorbox{shadecolorB}{\bf \large #1}}%
    \end{shaded} 
 }
}

上面的代码只为文本着色,而我想为整行或整个框着色。这是 MWE。

\documentclass[letterpaper,11pt]{article}
\usepackage{amssymb}
\newlength{\outerbordwidth}
\pagestyle{empty}
\raggedbottom
\raggedright
\usepackage[svgnames]{xcolor}
\usepackage{framed}
\usepackage{times}

%-----------------------------------------------------------
%Edit these values as you see fit

\setlength{\outerbordwidth}{2pt}  % Width of border outside of title bars
\definecolor{shadecolor}{gray}{1}  % Outer background color of title bars (0 = black, 1 = white)
%\definecolor{shadecolorB}{gray}{0.83}  % Inner background color of title bars
%\definecolor{shadecolorB}{gray}{0.86}
\definecolor{shadecolorB}{RGB}{246,213,216}


%-----------------------------------------------------------
%Margin setup


\setlength{\oddsidemargin}{-0.25in}


%-----------------------------------------------------------
%Custom commands
\newcommand{\resitem}[1]{\item #1 \vspace{-2pt}}
\newcommand{\resheading}[1]{\vspace{-15pt}
  \parbox{\textwidth}{
    \begin{shaded}
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{0pt}%
\framebox[\textwidth][l]{\setlength{\fboxsep}{2pt}\colorbox{shadecolorB}{\bf \large #1}}%
    \end{shaded} 
 }
}


\begin{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\resheading{Professional Experience}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

答案1

我不太确定我理解的是什么。我建议使用tikz文档是 Tikz & pgf 版本 3.1.10 手册。可以在 ctan 上找到https://ctan.org/pkg/pgf

  1. 我创建了一个带有阴影的矩形(第 2.14 节阴影(第 39 页))。

  2. 我创建了一个节点(第 2.21 节添加文本(第 45 页))。

    \documentclass[letterpaper,11pt]{article}
    
    \usepackage[svgnames]{xcolor}
    \usepackage{showframe}% <- comment ine the final document
    \usepackage{tikz}
    
    \definecolor{shadecolor}{gray}{1}
    \definecolor{shadecolorB}{RGB}{246,213,216}
    
    \newcommand{\resheading}[1]
    {%
    \noindent
    \begin{tikzpicture}
        \shade[left color=shadecolorB,right color=shadecolor]
        (0,0) rectangle (\textwidth,\baselineskip);
        \node[right]at (0,0.5\baselineskip){\bfseries\large #1};
    \end{tikzpicture}
    }
    
    \begin{document}
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \resheading{Professional Experience}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \end{document}
    

在此处输入图片描述

答案2

使用tblr表格很简单:

\documentclass[letterpaper,11pt]{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage{xcolor}
\definecolor{shadecolorB}{RGB}{246,213,216}
\usepackage{tabularray}


\newcommand{\resheading}[1]
{\noindent%
\begin{tblr}{X[l, font=\large\bfseries, bg=shadecolorB]}
   #1
\end{tblr}%
\medskip            % if after \resheading is needed some vertical space
}

\begin{document}
\resheading{Professional Experience}
\lipsum[66]
\end{document}

在此处输入图片描述

(红线表示文档页面布局)

相关内容