\documentclass{article}%https://github.com/readme/featured/nasa-ingenuity-helicopter
\usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{cascadia-code}
%\usepackage{paratype}\renewcommand{\familydefault}{\sfdefault}
\usepackage{xcolor}
\usepackage{gradient-text}
\usepackage[most]{tcolorbox}
\definecolor{backgroundd}{HTML}{232629}
\definecolor{myblue}{HTML}{1B1F23}
\newtcbox{\mybox}[1][myblue]{tcbox width=auto limited,colback=#1, colframe=#1, boxsep=0pt, size=small, arc=2mm, boxrule=10.4pt, top=2mm,bottom=2mm, right=2mm, left=2mm}
\newcommand{\cooltext}[1]{
{\fontfamily{\sfdefault}\selectfont
\mybox{\Large\bf\gradientRGB{#1}{72,107,234}{60,214,112}}
}
}
\begin{document}
a DSFASDF ASDF
ASD SAD FASD FSAD AS ASD
\cooltext{We wanted to make sure everyone was recognized for their contributions to this incredible human achievement.}
{\fontfamily{\sfdefault}\selectfont
This text uses a different font typeface
}
\end{document}
我想仅在 tcbox 中更改字体(所有其他文本应为默认样式或系列)并实现这样的结果
感谢您的任何帮助
答案1
您的\cooltext
命令执行的操作(相当于)\sffamily
是仅受分组约束的声明。由于您在顶层发出该命令,因此其效果将永远持续下去。
您需要\sffamily
在框内发出。
我建议在定义 tcbox 时选择字体,并将其名称更改为比 更具语义的名称\mybox
。
最后,请注意,该\bf
命令已被弃用约三十年了。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{gradient-text}
\usepackage[many]{tcolorbox}
\definecolor{backgroundd}{HTML}{232629}
\definecolor{myblue}{HTML}{1B1F23}
\newtcbox{\cooltextbox}[1][myblue]{
tcbox width=auto limited,
fontupper=\Large\sffamily\bfseries,
colback=#1,
colframe=#1,
boxsep=0pt,
size=small,
arc=2mm,
boxrule=10.4pt,
top=2mm,
bottom=2mm,
right=2mm,
left=2mm,
}
\newcommand{\cooltext}[1]{%
\cooltextbox{%
\gradientRGB{#1}{72,107,234}{60,214,112}%
}%
}
\begin{document}
Normal text
\cooltext{We wanted to make sure everyone was recognized for their
contributions to this incredible human achievement.}
Normal text
\end{document}
答案2
我改变了命令的顺序cooltext
。这使得其范围之外的文本变得不同。
\documentclass{article}%https://github.com/readme/featured/nasa-ingenuit
\usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{cascadia-code}
%\usepackage{paratype}\renewcommand{\familydefault}{\sfdefault}
\usepackage{xcolor}
\usepackage{gradient-text}
\usepackage[most]{tcolorbox}
\definecolor{backgroundd}{HTML}{232629}
\definecolor{myblue}{HTML}{1B1F23}
\newtcbox{\mybox}[1][myblue]{tcbox width=auto limited,colback=#1, colfra
\newcommand{\cooltext}[1]{%
\mybox{\Large\sffamily\bfseries\gradientRGB{#1}{72,107,234}{60,214,112}}
}
\begin{document}
a DSFASDF ASDF
ASD SAD FASD FSAD AS ASD
\cooltext{We wanted to make sure everyone was recognized for their contributions to this incredible human achievement.}
{\sffamily
This text uses a different font typeface
}
\end{document}