使用 tcolorbox 挤压自定义 stackoverflow 类似源代码框,并在单词周围留出恒定的空间

使用 tcolorbox 挤压自定义 stackoverflow 类似源代码框,并在单词周围留出恒定的空间

我尝试将我的字体系列更改tcolorbox为与 字体相似的字体source code in stackoverflow,但没有成功。

线的高度也不正确,有框的线和没有框的线是有区别的,有没有办法自动定义框的正确高度以消除这种影响?

在此处输入图片描述

盒子的代码是

   \makeatletter
    \newtcbox{\keywordmin}{on line, fontupper=\scriptsize\texttt, boxrule=0.5pt,arc=2pt,coltext=tangoBlack1,colback=tangoGrey1,colframe=tangoGrey1,boxsep=0pt,left=2pt,right=2pt,top=2pt,bottom=2pt}
    \makeatother

以下是完整的 MWE

% !TEX encoding =  UTF-8 Unicode
% -*- program: xelatex -*-
\documentclass[a4paper, 11pt,twoside, openright]{memoir}
\usepackage{mwe} % just for dummy images
\usepackage{amssymb}
\usepackage{amsmath,mathtools}
\usepackage{amstext}    % defines the \text command, needed here
\usepackage{array}
\usepackage{tcolorbox} 

\definecolor{tangoBlack1}{RGB}{0,0,0}
\definecolor{tangoGrey1}{RGB}{136,138,133}

\usepackage{sepfootnotes}
\newfootnotes{A}

\footmarkstyle{[#1]~}
\setlength{\footmarkwidth}{-1sp}
\setlength{\footmarksep}{0pt}
\setlength{\footparindent}{0pt}
\renewcommand{\foottextfont}{\scriptsize\raggedright}

\makeatletter
\newtcbox{\keywordmin}{on line, fontupper=\scriptsize\texttt, boxrule=0.5pt,arc=2pt,coltext=tangoBlack1,colback=tangoGrey1,colframe=tangoGrey1,boxsep=0pt,left=2pt,right=2pt,top=2pt,bottom=2pt}
\makeatother

\begin{document}

\Anotecontent{code_note}{This is a technical note with \keywordmin{Code} tag used to describe \keywordmin{keyword} in source code. This is a technical note with \keywordmin{Code} tag used to describe \keywordmin{keyword} in source code. I want to add some blablabla on the same line..I want to add some blablabla on the same line..I want to add some blablabla on the same line..I want to add some blablabla on the same line..  I want to add some blablabla on the same line..I want to add some blablabla on the same line.. }

This is a message which need a footnotes \Anote{code_note}.

\end{document}

更新1:

我使用基于@harish-kumar 答案的第一个答案和这个答案升级了这个问题问题更好地解释我的需要。

如果我增加挤压的尺寸(如extrude by=3ptextrude by=4pt)来构造一个更漂亮的盒子,挤压“吃”其他单词在周围。有没有办法tcolorbox保持彩色框和单词周围的正确间距(1pt)?

在此处输入图片描述

答案1

你可以用shrink tight,extrude by=2pt这种方法

\newtcbox{\keywordmin}{on line, fontupper=\scriptsize\ttfamily, boxrule=0.5pt,arc=2pt,coltext=tangoBlack1,colback=tangoGrey1,colframe=tangoGrey1, boxsep=0pt,shrink tight,extrude by=2pt}

这里shrink tight将整个颜色框缩小到上部的尺寸,同时extrude by = 2pt将颜色框向四面八方挤压2pt。内部宽度和边界框保持不变。

此外,您应该使用fontupper=\scriptsize\ttfamily而不是\texttt

代码:

% !TEX encoding =  UTF-8 Unicode
% -*- program: xelatex -*-
\documentclass[a4paper, 11pt,twoside, openright]{memoir}
\usepackage{mwe} % just for dummy images
\usepackage{amssymb}
\usepackage{amsmath,mathtools}
\usepackage{amstext}    % defines the \text command, needed here
\usepackage{array}
\usepackage{tcolorbox}

\definecolor{tangoBlack1}{RGB}{0,0,0}
\definecolor{tangoGrey1}{RGB}{136,138,133}

\usepackage{sepfootnotes}
\newfootnotes{A}

\footmarkstyle{[#1]~}
\setlength{\footmarkwidth}{-1sp}
\setlength{\footmarksep}{0pt}
\setlength{\footparindent}{0pt}
\renewcommand{\foottextfont}{\scriptsize\raggedright}

\makeatletter
\newtcbox{\keywordmin}{on line, fontupper=\scriptsize\ttfamily, boxrule=0.5pt,arc=2pt,coltext=tangoBlack1,colback=tangoGrey1,colframe=tangoGrey1, boxsep=0pt,shrink tight,extrude by=2pt}
\makeatother

\begin{document}

\Anotecontent{code_note}{This is a technical note with \keywordmin{Code} tag used to describe \keywordmin{keyword} in source code. This is a technical note with \keywordmin{Code} tag used to describe \keywordmin{keyword} in source code. I want to add some blablabla on the same line..I want to add some blablabla on the same line..I want to add some blablabla on the same line..I want to add some blablabla on the same line..  I want to add some blablabla on the same line..I want to add some blablabla on the same line.. }

This is a message which need a footnotes \Anote{code_note}.

\end{document}

在此处输入图片描述

相关内容