当前位置: 首页 > news >正文

【Typst】自定义彩色盒子

理论基础

使用with

使用with可以在不用搞函数的情况下,申明一些基于内部图形函数的元素。

你可以继续在他们基础上用with创建变体,或者在使用时用为他们设定不一样的参数

#let blue_box = rect.with(fill:rgb("#afe6f8"),inset: 10pt,width: 100%)#let red_box = blue_box.with(fill:red)#red_box(stroke: (left:4pt+orange))[123]

基于with的自定义彩色盒子

// 基础样式盒
#let mbox = rect.with(fill:luma(220),inset: 10pt,width: 100%)// 圆角框
#let r5_box = mbox.with(radius: 5pt)
#let r10_box = mbox.with(radius: 10pt)// 只有左侧边线
#let l4_gray = mbox.with(stroke: (left:4pt+gray),fill:none)
#let l4_orange = l4_gray.with(stroke: (left:4pt+orange))
#let l4_blue = l4_gray.with(stroke: (left:4pt+blue))
#let l4_red = l4_gray.with(stroke: (left:4pt+red))
#let l4_green = l4_gray.with(stroke: (left:4pt+green))// 左侧边线 + 浅色填充
#let l4_gray_box = mbox.with(stroke: (left:4pt+gray),fill:gray.lighten(80%))
#let l4_orange_box = mbox.with(stroke: (left:4pt+orange),fill:orange.lighten(80%))
#let l4_blue_box = mbox.with(stroke: (left:4pt+blue),fill:blue.lighten(80%))
#let l4_red_box = mbox.with(stroke: (left:4pt+red),fill:red.lighten(80%))
#let l4_green_box = mbox.with(stroke: (left:4pt+green),fill:green.lighten(80%))// 四面边框 + 无填充
#let bd_gray = mbox.with(stroke:gray,fill:none)
#let bd_orange = bd_gray.with(stroke:orange)
#let bd_blue = bd_gray.with(stroke:blue)
#let bd_red = bd_gray.with(stroke: red)
#let bd_green = bd_gray.with(stroke: green)#let bd_gray_box = mbox.with(stroke:gray,fill:gray.lighten(80%))
#let bd_orange_box = mbox.with(stroke:orange,fill:orange.lighten(80%))
#let bd_blue_box = mbox.with(stroke:blue,fill:blue.lighten(80%))
#let bd_red_box = mbox.with(stroke:red,fill:red.lighten(80%))
#let bd_green_box = mbox.with(stroke:green,fill:green.lighten(80%))
#let t = [这里是测试文本]#mbox[#t]
#r5_box[#t]
#r10_box[#t]#l4_gray[#t]
#l4_orange[#t]
#l4_blue[#t]
#l4_green[#t]
#l4_red[#t]#l4_gray_box[#t]
#l4_blue_box[#t]
#l4_orange_box[#t]
#l4_green_box[#t]
#l4_red_box[#t]#bd_gray[#t]
#bd_orange[#t]
#bd_blue[#t]
#bd_green[#t]
#bd_red[#t]#bd_gray_box[#t]
#bd_orange_box[#t]
#bd_blue_box[#t]
#bd_green_box[#t]
#bd_red_box[#t]

带标题的框

// 带标题的框
#let title_box(title,body,base_color:gray,align:top) = [#block(inset:(top: 15pt))[// 正文区带边框盒子#mbox(inset: (top:20pt,rest: 20pt),stroke: base_color,fill: base_color.lighten(80%))[#body]// 标题#let ddx = 5pt#if align == center {ddx = 0ptalign = top+center}#place(align,dy:-15pt,dx:ddx)[#mbox(width:auto,fill: base_color.darken(60%))[#text(white)[#title]]]]
]

http://www.lryc.cn/news/576831.html

相关文章:

  • 医疗AI智能基础设施构建:向量数据库矩阵化建设流程分析
  • 如何搭建基于RK3588的边缘服务器集群?支持12个RK3588云手机
  • Qt QGraphics简述及例程 - QGraphicsView、QGraphicsScene和QGraphicsItem
  • 深入剖析Nacos服务发现与注册,及如何基于LoadBalancer实现负载均衡
  • #华为昇腾#华为计算#昇腾开发者计划2025#
  • Redis分布式锁核心原理源码
  • #华为鲲鹏#华为计算#鲲鹏开发者计划2025#
  • Transformer结构与代码实现详解
  • 【电路笔记 TMS320F28335DSP】TI SCI (增强型的UART) 点对点异步串行通信接口
  • 【OpenGL学习】(八)图形变换
  • Oauth2 自定义设置token过期时间
  • 状态机编程实战 | 如何更优雅地处理字符串
  • 全新大模型开源,腾讯(int4能打DeepSeek) Vs 谷歌(2GB运行多模态)
  • Gemini-CLI:谷歌开源的命令行AI工具,重新定义开发者工作流
  • Ubuntu22 安装 RTX 5070 Ti Nvidia Driver 驱动
  • 自学嵌入式 day27 进程
  • mac系统快捷键及命令安装
  • 状态模式 - Flutter中的状态变身术,让对象随“状态“自由切换行为!
  • 边界的艺术:支持向量机与统计学习时代的王者
  • 设计模式-外观模式、适配器模式
  • 【数据挖掘】聚类算法学习—K-Means
  • YOLOv12_ultralytics-8.3.145_2025_5_27部分代码阅读笔记-conv.py
  • 设备预测性维护和异常检测系统设计方案
  • 【HuggingFace】模型下载至本地访问
  • Git安装全攻略:避坑指南与最佳实践
  • C++ 格式化输入输出
  • 人工智能时代的职业替代风险与应对策略分析
  • MySQL技巧
  • 性能分析专栏 -- top命令
  • 【修电脑的小记录】连不上网