2
\documentclass[a4paper]{article}
\usepackage[most]{tcolorbox}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\begin{document}

% Code Block I %
MM%
\begin{tcolorbox}[blankest, nobeforeafter,bottom=0pt,boxsep=0pt, opacitytext=0.2]
  \color{red}MM
\end{tcolorbox}%
MM\\
%%%%%%%%%%%%%%%%%%%%%%%%%%

% Code Block II %
MM%
\begin{tcolorbox}[blankest, nobeforeafter,bottom=0pt,boxsep=0pt, opacitytext=0.2]
  \color{red}地方
\end{tcolorbox}%

\end{document}

From the "code block I", I want to get six continuous characters "M". However, the typeset gives unwanted whitespace. I think this is because the width of tcolorbox is default of \textwidth. How can I get a tcolorbox which width changes with its content?

From the typeset of "code block II" which contains non-ascii characters(here is CJK,for example), we can see that there is unalignment in height between characters. How to align ascii characters with CJK characters?

PS: I know \tcbox may be a soluntion. But I want line-break sometimes. So tcolorbox must be choosed.

enter image description here

11
  • tcbox adjust their width to thier contents, but tcolorbox uses linewidth as their defult width, unless you use width option.
    – Ignasi
    May 3, 2018 at 10:32
  • In any case, your code doesn't compile,[most] option to package tcolorbox is missing. And my system complains about CJK characters.
    – Ignasi
    May 3, 2018 at 10:33
  • Thanks @lgnasi, do you have any idea how to break lines in tcbox?
    – lyl
    May 3, 2018 at 10:35
  • For box alignment use baseline or box align options (page 79)
    – Ignasi
    May 3, 2018 at 10:35
  • Something like this? tex.stackexchange.com/questions/125162/… May 3, 2018 at 10:36

1 Answer 1

4

You don't need tcolorbox (which creates boxes and so make line breaking difficult) only to get colored, transparent text.

\documentclass[a4paper]{article}
\usepackage{pgf,xcolor}

\begin{document}

MM%
\textcolor{red}{MM}%
\textcolor{red}{\pgfsetfillopacity{0.5}MM\pgfsetfillopacity{1}}
MM

\end{document}

opacity settings don't respect tex groups, so you must reset them explictly.

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .