design legend and toc element formular and fix some bugs