\documentclass[hyperref,a4paper,openany,UTF8]{ctexbook}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{indentfirst}
\usepackage{latexsym}
\usepackage{titlesec}
\usepackage{xeCJK}
\usepackage[no-files]{xsim}
\usepackage{lastpage}
 
\xsimsetup{
  load-style = layouts
}
\DeclareExerciseType{eg}
{exercise-env = eg,
solution-env = egans,
exercise-name ={例},
solution-name ={例},
%exercise-template = item ,
%solution-template = item
exercise-template =margin,
solution-template =margin,
%ex-heading  = \subsection* ,
%sol-heading  = \subsection*
}
\renewcommand*\theeg{\arabic{eg}}

\DeclareExerciseType{ex}
{exercise-env = ex,
solution-env = exans,
exercise-name ={},
solution-name ={},
%exercise-template = item ,
%solution-template = item
exercise-template =margin,
solution-template =margin,
%ex-heading  = \subsection* ,
%sol-heading  = \subsection*
}
\renewcommand*\theex{(\arabic{ex})}

\title{测试}
\author{测试}

\date{\today}

\begin{document}
\maketitle
\tableofcontents

\part{题}
\chapter{测试}
\section{测试一}
\subsection{例题一}
\begin{eg}
eg1
\end{eg}
\begin{egans}
eg1
\end{egans}

\begin{ex}
ex1
\end{ex}
\begin{exans}
ex1
\end{exans}

\subsection{例题二}
\begin{eg}
eg2
\end{eg}
\begin{egans}
eg2
\end{egans}

\begin{ex}
ex2
\end{ex}
\begin{exans}
ex2
\end{exans}

\section{测试二}
\subsection{例题三}
\begin{eg}
eg3
\end{eg}
\begin{egans}
eg3
\end{egans}

\begin{ex}
ex3
\end{ex}
\begin{exans}
ex3
\end{exans}

\part{答案}
\printsolutions[chapter=1,section=1,headings-template=none]
\printsolutions[chapter=1,section=2,headings-template=none]
\end{document}
